How to enable SSL for SmtpClient in Web.config

前端 未结 10 1141
再見小時候
再見小時候 2020-12-05 07:03

Is there a way to set the EnableSSL from the web.config?

I could set this property in code, but that wouldn\'t work for the Simple Mail Web Event and other classes t

10条回答
  •  萌比男神i
    2020-12-05 08:00

    I have a dirty workaround (until .NET 4.0 comes out). Instead of changin my code it relies on the used port to determine if SSL is required or not.

    var client = new SmtpClient();
    client.EnableSsl = client.Port == 587 || client.Port == 465;
    // This could also work
    //client.EnableSsl = client.Port != 25;
    

    I said it was a dirty hack, but it working fine for the different configurations that we encounter.

提交回复
热议问题