由谷歌
MailMessage oMail = new MailMessage();
SmtpClient smtpClient = new SmtpClient();
string FromMailID = "[email protected]";
string UserName = "GmailUsername";
string Password = "GmailPassword";
MailAddress fromAddress = new MailAddress(FromMailID);
if (FilePath != "")//If attached file otherwise comment
{
Attachment PDFfile = new Attachment(FilePath);
oMail.Attachments.Add(PDFfile);
}
oMail.From = fromAddress;
oMail.To.Add(ToMailID);
oMail.Subject = Subject;
oMail.IsBodyHtml = true;
oMail.Body = Mailcontent.ToString();
smtpClient.Host = "smtp.gmail.com"; // We use gmail as our smtp client
smtpClient.Port = 25;//localhost
smtpClient.UseDefaultCredentials = false;
smtpClient.EnableSsl = true;
smtpClient.UseDefaultCredentials = true;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.Credentials = new System.Net.NetworkCredential(UserName, Password);
smtpClient.Send(oMail);
服務器響應嘗試使用發送郵件驗證碼爲:5.5.1需要驗證。 檢查gmail安全 如果遠程服務器從服務器登錄到gmail帳戶 –