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

  SmtpClient smtpServer = new SmtpClient("smtp.163.com");
smtpServer.Port = ;
smtpServer.Credentials = new System.Net.NetworkCredential("feiyang", "");
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","");
smtp.SendAsync("feiyanghenan@163.com", "1234@qq.com", "平台用户关联验证", "验证码:" + new Random().Next(, ).ToString(), "userToken");

网易邮箱设置获取(NetworkCredential)

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

上一篇:HM NIS Edit 2.0.3 Win32 Error. Code:740.请求的操作需要提升


下一篇:Java继承中成员方法的overload(重载/过载)