ASP.NET发送邮件

MailMessage msg = new MailMessage();

    msg.From = settings.SystemEmailAccount;
    msg.To = to;
    msg.Subject = subject;
    msg.Body = body;

    if(settings.SmtpAuthenticationRequired)
    {
     msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1" );
     msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", settings.SystemEmailAccount);
     msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", settings.SystemEmailAccountPassword);
    }

    if(settings.SmtpPort != 25)
    {
     msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", settings.SmtpPort.ToString());
    }

    if(settings.SmtpUseSSL)
    {
     msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "1");
    }

    SmtpMail.SmtpServer = settings.SmtpServer;
    SmtpMail.Send(msg);

posted on 2006-04-06 19:16  自由.Net  阅读(170)  评论(0编辑  收藏  举报