C#用网易邮箱发送邮件(同步异步)
Posted 名扬博客
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C#用网易邮箱发送邮件(同步异步)相关的知识,希望对你有一定的参考价值。
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("[email protected]");//和上面的对应 mail.To.Add("[email protected]"); 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("[email protected]", "[email protected]", "平台用户关联验证", "验证码:" + new Random().Next(1111, 9999).ToString(), "userToken");
网易邮箱设置获取(NetworkCredential)
http://jingyan.baidu.com/article/ff42efa93af8d9c19f22024e.html
以上是关于C#用网易邮箱发送邮件(同步异步)的主要内容,如果未能解决你的问题,请参考以下文章