天天看點

伺服器認證發送郵件

參數說明

Subject:郵件标題

ToAddress:目标郵箱

FromAddress:發送人郵箱

Body:郵件内容

public static void SendMail(String Subject,String ToAddress,String FromAddress,String Body)

{

MailMessage mail = new MailMessage();

mail.To = ToAddress;

mail.From = FromAddress;

mail.Subject = Subject;

mail.Body = Body;

//以下内容為伺服器認證語句

mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication

//使用者名

mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "UserID");

//郵箱密碼

mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "Password");

//寫入smtp伺服器名字

SmtpMail.SmtpServer = "smtp.163.com";

SmtpMail.Send( mail );

}

繼續閱讀