码迷,mamicode.com
首页 > Windows程序 > 详细

c# 邮件发送功能

时间:2016-02-04 10:37:57      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:

//统一由一个邮箱发送录用通知
            string strfrom = "";//发件人邮箱地址
            string strpow = "";//邮箱密码
            string strserver = "";//发送邮件服务器
            string strto = "";//收件人地址
            string strtitle = "邮件标题";
            string strdody = "<div style=‘font-size:14px;‘>邮件内容</div>";

            string file1 = Server.MapPath("附件.doc");//附件地址1
            string file2 = Server.MapPath("附件.pdf");//附件地址2
            //发送邮件方法
            //Send(strserver, strfrom, strpow, strto, strtitle, strdody);

            SmtpClient client = new SmtpClient(strserver);

            // client.UseDefaultCredentials = false;
            client.UseDefaultCredentials = true;
            client.Credentials = new System.Net.NetworkCredential(strfrom, strpow);
            client.DeliveryMethod = SmtpDeliveryMethod.Network;

            Byte[] b = Encoding.Default.GetBytes(strdody);
            strdody = Encoding.GetEncoding("gb2312").GetString(b).ToString();

            //建立邮件附件类的一个对象,语法格式为System.Net.Mail.Attachment(文件名,文件格式)  
            System.Net.Mail.Attachment myAttachment1 = new System.Net.Mail.Attachment(
            file1, System.Net.Mime.MediaTypeNames.Application.Octet);
            System.Net.Mail.Attachment myAttachment2 = new System.Net.Mail.Attachment(
            file2, System.Net.Mime.MediaTypeNames.Application.Octet);

            MailMessage message = new MailMessage(strfrom, strto, strtitle, strdody);            
            message.Attachments.Add(myAttachment1);//用smtpclient对象里attachments属性,添加上面设置好的myattachment
            message.Attachments.Add(myAttachment2);
            message.BodyEncoding = Encoding.UTF8;
            message.IsBodyHtml = true;

            client.Send(message);

发送邮件中有很多默认的方法,若以后遇到问题随时更新!

c# 邮件发送功能

标签:

原文地址:http://www.cnblogs.com/mmengblog/p/5181025.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!