asp.net自带的MailMessage其实很好用的,还支持SMTP

代码如下:
using System.Web.Mail;
                        
public static void SendMail(string to, string subject, string body)
        
{
            MailMessage mail 
= new MailMessage();
            mail.From 
= "\"发送者的名字\" <你的邮箱地址>";//设定发件人名字和地址(必须填写)
            mail.BodyFormat = MailFormat.Html;//用html格式
            mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate""1"); //basic authentication
            mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername","邮箱用户名"); //设定SMTP验证的用户名
            mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword""邮箱密码"); //设定SMTP验证的密码        
            SmtpMail.SmtpServer = "smtp服务器";//设定SMTP服务器地址,如smtp.163.com
            mail.To = to ;//设定收件人地址(必须填写)。
            mail.Subject = subject;
            mail.Body 
= body;
            SmtpMail.Send(mail);

        }

大家注意到mail.From = "\"发送者的名字\" <你的邮箱地址>"; 了吗?
发送者的名字是你想邮件用什么名字发送,用什么名字都行,如:
mail.From = "\"microtea的小屋\" <microtea@msn.com>";
posted on 2005-03-11 11:51  microtea  阅读(1115)  评论(0编辑  收藏  举报