确保使用
System.Net.Mail而不是不推荐使用
System.Web.Mail。使用SSL
System.Web.Mail会导致hacky扩展的混乱。
using System.Net;using System.Net.Mail;var fromAddress = new MailAddress("from@gmail.com", "From Name");var toAddress = new MailAddress("to@example.com", "To Name");const string fromPassword = "fromPassword";const string subject = "Subject";const string body = "Body";var smtp = new SmtpClient{ Host = "smtp.gmail.com", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(fromAddress.Address, fromPassword)};using (var message = new MailMessage(fromAddress, toAddress){ Subject = subject, Body = body}){ smtp.Send(message);}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)