Must issue a STARTTLS command first
sentjurv opened this issue · 6 comments
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?
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.
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
You would need to add
SecureSocketOption = SecureSocketOptions.StartTls
in theEmailConnectionInfo
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+?
I resolved with Log.CloseAndFlush(); after log
I ended up just using NLog
, they seem to support the STARTTLS
protocol out of the box for .NET 6.
3.0.0-dev on NuGet now enables EmailConnectionInfo.SecureSocketOption
for all platforms. Any and all help testing/polishing that version appreciated.