asp.net发送邮件的方式不少,我经常用这样两种:
一,System.Web.Mail 和System.Web.Util
public static void SendMail(string from , string to, string subject, string body)
{
MailMessage email = new MailMessage();
email.From = from;
email.To = to;
email.Subject = subject;
email.Body = body;
SmtpMail.Send(email);
}
public static void CDOsendmail(string from, string to, string subject, string body, string userName, string password, string smtpServer)
{
CDO.Message Msg = new CDO.Message();
Msg.From = from;
Msg.To = to;
Msg.Subject = subject;
Msg.HTMLBody = "<html><body>"+body
+"</body></html>";
CDO.IConfiguration Config = Msg.Configuration;
ADODB.Fields oFields = Config.Fields;
oFields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value = 2;
oFields["http://schemas.microsoft.com/cdo/configuration/sendusername"].Value=userName;
oFields["http://schemas.microsoft.com/cdo/configuration/sendpassword"].Value=password;
oFields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].Value=1;
oFields["http://schemas.microsoft.com/cdo/configuration/languagecode"].Value=0x0804;
oFields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value=smtpServer;
oFields.Update();
Msg.BodyPart.Charset = "gb2312";
Msg.HTMLBodyPart.Charset = "gb2312";

Msg.Send();
Msg = null;
}两种方式的成功率差距很大,后者很高。

浙公网安备 33010602011771号