public class MailHelper
{
private static string fromAddr = "from@xx.com";//发送邮箱
private static string fromPwd = "abcd";//发送邮箱密码
private static string smtpAddr = "smtp.exmail.qq.com";//smtp地址,样例使用的是腾讯企业邮箱地址
private static int smtpPort = 465;//smtp端口号
private static string usessl = "true";//是否使用ssl加密
///
/// 发送邮件
///
/// 接收邮箱
/// 邮件主题
/// 邮件内容
public static void SendEmailByWebMail(string toAddr, string subject, string body)
{
System.Web.Mail.MailMessage mail = new System.Web.Mail.MailMessage();
try
{
mail.To = toAddr;
mail.From = fromAddr;
mail.Subject = "邮件测试";
mail.BodyFormat = System.Web.Mail.MailFormat.Text;
mail.Body = "测试正文";
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", fromAddr);
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", fromPwd);
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", smtpPort);
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", usessl);
System.Web.Mail.SmtpMail.SmtpServer = smtpAddr;
System.Web.Mail.SmtpMail.Send(mail);
}
catch (Exception ex)
{
ex.ToString();
}
}
}