Send mail using localhost SMTP

后端 未结 6 1988
失恋的感觉
失恋的感觉 2020-12-14 07:41

I am trying to setup SMTP server on IIS for sending mails. The SMTP server is intended to be used by the ASP.NET code in C#.

I was previously using gmail smtp where

6条回答
  •  没有蜡笔的小新
    2020-12-14 08:14

    When you are using the local IIS SMTP service, set the DeliveryMethod to PickupDirectoryFromIis. For example:

      smtpClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
    

    This totally bypasses the network layer, and writes the messages directly to disk. Its much faster than going through the chatty SMTP protocol.

    When you using the above code, it means you can get rid of this part of your code:

    smtpClient.UseDefaultCredentials = false;
    smtpClient.Host = "smtp.gmail.com";
    smtpClient.Port = 587;
    smtpClient.Credentials = new NetworkCredential(uname,pwd);
    smtpClient.EnableSsl = true;
    

提交回复
热议问题