serilog / serilog-sinks-email

A Serilog sink that writes events to SMTP email
Apache License 2.0
72 stars 68 forks source link

Must issue a STARTTLS command first #102

Closed sentjurv closed 9 months ago

sentjurv commented 3 years ago

Hello,

I'm trying to configure serilog to send me emails:

            .WriteTo.Email(new EmailConnectionInfo
            {
                FromEmail = "xxx@gmail.com",
                ToEmail = "xxx@gmail.com",
                MailServer = "smtp.gmail.com",
                NetworkCredentials = new NetworkCredential
                {
                    UserName = "xxx@gmail.com",
                    Password = "password"
                },
                EnableSsl = true,
                Port = 587,
                EmailSubject = "HRIS Integration Exception"
            }, restrictedToMinimumLevel: LogEventLevel.Error, batchPostingLimit: 1)

But have the followinf exception: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first.

Could you please advise?

0xced commented 2 years ago

You would need to add SecureSocketOption = SecureSocketOptions.StartTls in the EmailConnectionInfo instance.

Note that this option is only available when targeting .NET Standard (1.3, 2.0 or 2.1) but not when targeting .NET Framework.

See also #96.

prandoz commented 2 years ago

Hi I try send mail with gmail, but without success. I don't understand where put SecureSocketOption for StartTls. In my EmailConnectionInfo i can't put. I use the 2.4.0 version of Serilog.Skins.Email. Thank you

KieranDevvs commented 1 year ago

You would need to add SecureSocketOption = SecureSocketOptions.StartTls in the EmailConnectionInfo instance.

Note that this option is only available when targeting .NET Standard (1.3, 2.0 or 2.1) but not when targeting .NET Framework.

See also #96.

Why is this restricted to net standard? Does not include net core & .NET 5+?

prandoz commented 1 year ago

I resolved with Log.CloseAndFlush(); after log

KieranDevvs commented 1 year ago

I ended up just using NLog, they seem to support the STARTTLS protocol out of the box for .NET 6.

nblumhardt commented 9 months ago

3.0.0-dev on NuGet now enables EmailConnectionInfo.SecureSocketOption for all platforms. Any and all help testing/polishing that version appreciated.