这是我的剧本:
var fromAddress = new MailAddress("myemail@gmail.com");
var toAddress = new MailAddress("myemail@gmail.com");
const string fromPassword = "mypassword";
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);
}
效果很好,但我还没有找到添加附件的方法。是的,我知道这个网站有例子,但我找不到会发送附件