这是我的脚本:
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);
}
它运作良好,但我还没有想出一种添加附件的方法。是的,我知道这个网站有示例,但我找不到可以发送附件的示例