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);

相关文章: