我使用以下代碼從此答案Sending email in .NET through Gmail。我遇到的麻煩是給電子郵件添加附件。我將如何使用下面的代碼添加附件?使用C#向電子郵件添加附件
using System.Net.Mail;
var fromAddress = new MailAddress("[email protected]", "From Name");
var toAddress = new MailAddress("[email protected]", "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);
}
在此先感謝。
這,謝謝大家。 如此簡單而有效的+1 – Bauer 2015-08-21 19:13:11