//这里的邮箱帐号和密码一定要和下面配置文件中设置的邮箱的帐号和密码一致
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "xxxxxxxxx");//邮箱帐号,比如Test11@126.com帐号为:Test11
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "xxxxxxxx");//邮箱密码
//这个是指明邮件服务器的端口,可以不指定
//message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "25");
foreach (string str in strTemp.Split(';'))
{
if (reg.IsMatch(str))
{
message.To = str;
message.BodyEncoding = System.Text.Encoding.UTF8;
System.Web.Mail.SmtpMail.SmtpServer = strSMTPServer;
System.Web.Mail.SmtpMail.Send(message);
}
}
bState = true;
}
catch (Exception ex)
{
System.IO.File.AppendAllText("C:\\Mail_Log.ini", string.Format("{0:yyyy/MM/dd HH:mm:ss}\r\n{1}\r\n\r\n", DateTime.Now, ex.Message));
bState = false;
strErrorMsg = ex.Message;
}
return bState;
}
//测试发送邮件
{
try
{
Email.SendEmail("xxxxxx@163.com", "", "Test Email", "Test Send Email");
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
邮件在webconfig文件中配置如下: