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

相关文章:

  • 2021-11-15
  • 2021-07-13
猜你喜欢
  • 2021-07-04
  • 2021-05-27
  • 2021-06-18
  • 2022-03-09
相关资源
相似解决方案