服务器认证发送邮件

参数说明
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 );
}

你可能感兴趣的:(服务器认证发送邮件)