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

C#用网易邮箱发送邮件(同步异步)

时间:2016-06-28 10:47:10      阅读:258      评论:0      收藏:0      [点我收藏+]

标签:

  SmtpClient smtpServer = new SmtpClient("smtp.163.com");
                smtpServer.Port = 25;
                smtpServer.Credentials = new System.Net.NetworkCredential("feiyang", "1234");
                smtpServer.EnableSsl = true;
                MailMessage mail = new MailMessage();
                mail.From = new MailAddress("feiyang@163.com");//和上面的对应
                mail.To.Add("1234@qq.com");
                mail.Subject = "会员注册信息";//标题
                mail.SubjectEncoding = Encoding.UTF8;
                mail.Body = mailBoby;
                mail.Priority = System.Net.Mail.MailPriority.High;//邮件优先级
                mail.IsBodyHtml = true;
                smtpServer.SendAsync(mail, "userToken");//异步发送第二个参数时一个用户定义对象,此对象将被传递给完成异步操作时所调用的方法,参数默认即可
// smtpServer.Send(mail);//同步发送
 System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
                    smtp.Host = "smtp.163.com";
                    smtp.Credentials  =new System.Net.NetworkCredential("feiyang","1234");
                    smtp.SendAsync("feiyanghenan@163.com", "1234@qq.com", "平台用户关联验证", "验证码:" + new Random().Next(1111, 9999).ToString(), "userToken");

网易邮箱设置获取(NetworkCredential)

http://jingyan.baidu.com/article/ff42efa93af8d9c19f22024e.html

C#用网易邮箱发送邮件(同步异步)

标签:

原文地址:http://www.cnblogs.com/wangboke/p/5622389.html

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