using System.Web.Mail发送邮件

【转】http://blog.csdn.net/wandersongsong/archive/2006/03/31/645294.aspx

首先在程序开头添加引用:
using System.Web.Mail;
程序主体部分:
MailMessage mailMessage = new MailMessage();
mailMessage.To =(收件人的EMAIL地址);
mailMessage.From=(发件人的EMAIL地址);
mailMessage.Body=(邮件的内容,可以是HTML文件);
mailMessage.Subject="(邮件标题!)";
mailMessage.BodyFormat = MailFormat.Html ;(说明发送的是HTML代码)
string strMailName ="(发件人的用户名)";
string strPassWord="(发件人的密码)";
mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1" );     //认证类型
mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", strMailName );     //认证用户名
mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", strPassWord );    //认证密码

string smtpServer = (SMTP服务器地址如218.108.36.229);
SmtpMail.SmtpServer = smtpServer;   
SmtpMail.Send( mailMessage );

posted @ 2012-02-26 00:06  sagamaw  阅读(222)  评论(0)    收藏  举报