Dotnet1.1&2.0 SendMail detail to explain
/**********************************************************************
**
** DotNet1.1环境下 Code CreateBy 伴老 2005.6.14
** http://blog.csdn.net/abandonship/archive/2008/12/22/3580975.aspx
**
**********************************************************************/
using System.Web.Mail;
public void _Dotnet1.1SendMail()
{
strMessage = ""; //定义错误信息
MailMessage mailMsg = new MailMessage();
mailMsg.From = strMailFrom;
mailMsg.To = strMailTo;
mailMsg.Subject = strMailTitle;
mailMsg.Priority = MailPriority.High; //邮件级别,.High、.Low、.Normal
mailMsg.BodyFormat = MailFormat.Text; //邮件形式,.Text、.Html
mailMsg.Body = strEmailBody;
mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //设置支持服务器验证
mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", strMailFrom); //设置用户名
mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", strPsd); //设置用户密码
SmtpMail.SmtpServer = strMailSMTP; //or SmtpMail.SmtpServer.Insert( 0, strMailSMTP);
try
{
//发送邮件
SmtpMail.Send( mailMsg );
}
catch( Exception Message )
{
strMessage = "发送失败" + Message.Message.ToString();
}
if( strMessage != "" )
{
Response.Write(strMessage );
}
else
{
Response.Write("发送成功!");
}
}
/**********************************************************************
**
** DotNet2.0环境下 Code CreateBy 伴老 2006.11.23
** http://blog.csdn.net/abandonship/archive/2008/12/22/3580975.aspx
**
**********************************************************************/
using System.Net.Mail;
public void _Dotnet2.0SendMail()
{
strMessage = "";
MailMessage mailMsg = new MailMessage();
mailMsg.To.Add(new MailAddress("收件人邮箱集合")); //设置收件人的邮件地址
mailMsg.From = new MailAddress("发件人邮箱地址"); //设置发送者的邮件地址
mailMsg.Subject = strMailTitle; //设置邮件主题
mailMsg.Priority = MailPriority.High; // 设置邮件级别:.High、.Low、.Normal
mailMsg.IsBodyHtml = true; //设置邮件形式:是否为HTML格式
mailMsg.SubjectEncoding = System.Text.Encoding.UTF8;
mailMsg.BodyEncoding = System.Text.Encoding.UTF8;
mailMsg.Body = strEmailHTML;
//设置发送邮件服务器
SmtpClient client = new SmtpClient(strMailSMTPServer);
client.Credentials = new System.Net.NetworkCredential("发件人邮箱", "发件人邮箱密码");
client.EnableSsl = true; //经过SSL加密
try
{
client.Send(mailMsg);
}
catch (Exception Message)
{
strMessage = "发送失败" + Message.Message.ToString();
}
if( strMessage != "" )
{
Response.Write(strMessage );
}
else
{
Response.Write("发送成功!");
}
}