本文共 933 字,大约阅读时间需要 3 分钟。
来自:http://outofmemory.cn/code-snippet/1520/c-usage-Gmail-fayoujian-achieve
如下代码实现用Gmail发邮件。遗憾的是我朝用google越来越难了!
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);}
转载地址:http://qrunb.baihongyu.com/