我不是依靠主机发送电子邮件,而是在考虑使用我的 Gmail 帐户发送电子邮件。这些电子邮件是发给我在演出中演奏的乐队的个性化电子邮件。
有可能做到吗?
确保使用System.Net.Mail而不是不推荐使用System.Web.Mail。使用SSL System.Web.Mail会导致hacky扩展的混乱。
System.Net.Mail
System.Web.Mail
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); }