G. *_*nos 5 appsettings serilog asp.net-core
EnableSsl = false我正在尝试在 my 中使用,但用于连接的smtp 客户端EmailConnectionInfo似乎正在尝试使用 SSL,因为默认设置为. 当我手动创建客户端并使用重载时,它起作用了。smtpSecureSocketOptionsAutoSecureSocketOptions = None
错误:
Failed to send email: MailKit.Security.SslHandshakeException: An error occurred while attempting to establish an SSL or TLS connection.
The SSL certificate presented by the server is not trusted by the system for one or more of the following reasons:
1. The server is using a self-signed certificate which cannot be verified.
2. The local system is missing a Root or Intermediate certificate needed to verify the server's certificate.
3. The certificate presented by the server is expired or invalid.
See https://github.com/jstedfast/MailKit/blob/master/FAQ.md#InvalidSslCertificate for possible solutions. ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.
Run Code Online (Sandbox Code Playgroud)
解决方法:
我正在设置ServerCertificateValidationCallback为true
当在 my 中使用时Program.cs,它有效:
Failed to send email: MailKit.Security.SslHandshakeException: An error occurred while attempting to establish an SSL or TLS connection.
The SSL certificate presented by the server is not trusted by the system for one or more of the following reasons:
1. The server is using a self-signed certificate which cannot be verified.
2. The local system is missing a Root or Intermediate certificate needed to verify the server's certificate.
3. The certificate presented by the server is expired or invalid.
See https://github.com/jstedfast/MailKit/blob/master/FAQ.md#InvalidSslCertificate for possible solutions. ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试将所有 serilog 设置包含Email sink在无法读取的位置时(我的假设appsettings.json)"ServerCertificateValidationCallback": "(senderX, certificate, chain, sslPolicyErrors) => true"
我的appsettings.json
"Serilog": {
"Using": [ "Serilog.Sinks.File","Serilog.Sinks.Email" ],
"MinimumLevel": "Information",
"WriteTo": [
...
{
"Name": "Email",
"Args": {
"connectionInfo": {
"MailServer": "{SMTP IP}",
"Port": {PORT},
"EnableSsl": false,
"FromEmail": "{email}",
"ToEmail": "{email}",
"EmailSubject": "Something went wrong",
"ServerCertificateValidationCallback": "(s, cert, chain, sslPolicyErrors) => true"
},
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}",
"restrictedToMinimumLevel": "Warning",
"batchPostingLimit": 1
}
}
],
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ]
}
...
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
编辑:我打开的githut 问题
我能够利用其他一些问题来完成此工作,并且无需支持回调就可以直接通过配置进行设置。这个问题的答案(/sf/answers/4193993541/)特别有帮助。如果你按照他的例子做一些修改。
您可以将 添加ServerCertificateValidationCallback = (senderX, certificate, chain, sslPolicyErrors) => true到扩展类EmailConnectionInfo中SerilogEmailExtension
调整 Serilog 配置“Using”语句以包含编译的应用程序的名称,以便它可以找到扩展类而不是“MyApp”:
"Using": [ "Serilog", "Serilog.Sinks.Console", "Serilog.Sinks.File", "MyApp" ],
Run Code Online (Sandbox Code Playgroud)
这应该让您实现配置驱动的所有内容,并且仍然添加回调以绕过异常。
| 归档时间: |
|
| 查看次数: |
3532 次 |
| 最近记录: |