Ben Guri
Ben Guri

Reputation: 348

NLog Mail target timeouts

I'm trying to use NLog's mail target to send emails through a secured (SSL) smtp server. here is my configuration:

<target type="Mail"
        name="MailTarget"
        layout="${message}"
        encoding="UTF-8"
        html="False"
        addNewLines="False"
        subject="hi8766"
        to="[email protected]"
        from="[email protected]"
        body="${message}"
        smtpUserName="ben.g"
        enableSsl="True"
        smtpPassword="12345"
        smtpAuthentication="Basic"
        smtpServer="smtp.MyCompany.com"
        smtpPort="465"
        deliveryMethod ="Network"
        pickupDirectoryLocation=""
        timeout="20000"/>

however when I use logger.info(message)nothing happens. I turned on NLog's internal logging on and also started Wireshark, on the internal logs I see:

2016-02-05 10:46:54.3968 Debug Sending mail to [email protected] using smtp.MyCompany.net.il:465 (ssl=True)
2016-02-05 10:47:14.4526 Error System.Net.Mail.SmtpException: The operation has timed out.
   at System.Net.Mail.SmtpClient.Send(MailMessage message)
   at NLog.Internal.MySmtpClient.NLog.Internal.ISmtpClient.Send(MailMessage )
   at NLog.Targets.MailTarget.ProcessSingleMailMessage(List`1 events)

the thing is that i can see the SYN-SYN/ACK-ACK transmission but then the ssl negotiation doesn't start and everything stops untill the FIN from the client. this is weird because I have compared the network behavior with outlook on the same setting and the ssl does start and everything works fine and email is sent.

Upvotes: 1

Views: 1273

Answers (1)

Julian
Julian

Reputation: 36740

This could be a .Net bug, described at: http://blogs.msdn.com/b/webdav_101/archive/2008/06/02/system-net-mail-with-ssl-to-authenticate-against-port-465.aspx

TL;DR: SSL + port 465 (implicit SSL) is not supported in .Net. You can only use SSL + port 25 (explicit SSL)

There is now a GitHub issue for this. If we can build some workarounds in NLog for this, let us know.

Upvotes: 2

Related Questions