【发布时间】:2017-02-02 03:37:18
【问题描述】:
void sendMail(string invoiceNumber)
{
try
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("Smtp.gmail.com");
mail.From = new MailAddress("*******@gmail.com");
mail.To.Add("******@gmail.com");
mail.Subject = "Test Mail - 1";
mail.Body = invoiceNumber;
mail.Subject = "PDFs Attached";
DirectoryInfo di = new DirectoryInfo(@"C:\Users\User\Desktop\test\");
foreach (var file in di.GetFileSystemInfos("*.pdf*"))
mail.Attachments.Add(new Attachment(file.FullName));
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("*******@gmail.com", "*********");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
【问题讨论】:
-
欢迎来到 SO。您应该阅读有关我们如何编写格式良好的问题的信息。 rene 已经提到的链接是一个非常好的开始。这次,我为您编写了代码。然而,这仍然不是一个问题。这只是带有
mail was not sending的代码。你必须描述出了什么问题?到目前为止,您的发现是什么以及您遇到的问题。