首页 > 解决方案 > Netcore 2.2 - Docker 容器无法发送邮件

问题描述

我目前正在将一个应用程序部署到 docker 容器中,该应用程序具有发送邮件的功能(基于 c# netcore 2.2)但我无法发送邮件(虽然意味着我可以从本地主机发送邮件)docker 中的异常消息

System.ComponentModel.Win32Exception:GSSAPI 操作失败并出现错误 - 未指定的 GSS 失败。次要代码可能会提供更多信息(找不到领域“xxx.yyyy”的 KDC)。在 System.Net.Security.NegotiateStreamPal.AcquireCredentialsHandle(String package, Boolean isServer, NetworkCredential credential) 在 System.Net.NTAuthentication.Initialize(Boolean isServer, String package, NetworkCredential credential, String spn, ContextFlagsPal requestedContextFlags, ChannelBinding channelBinding) 在系统。 System.Net.Mail.SmtpConnection.SetContextAndTryAuthenticate(ISmtpAuthenticationModule 模块,NetworkCredential 凭据,
在 System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port) 在 System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port) 在 System.Net.Mail.SmtpClient.GetConnection() 在 System.Net .Mail.SmtpClient.Send(MailMessage message) --- 内部异常堆栈跟踪结束 --- 在 System.Net.Mail.SmtpClient.Send(MailMessage message)

我尝试了谷歌的一些帮助,但不能,所以请帮助我,谢谢

标签: c#dockeremail

解决方案


当您发送具有 GSSAPI 身份验证类型的邮件时,Linux 上的 dotnet 似乎存在问题: https://github.com/dotnet/runtime/issues/2174https://github.com/dotnet/runtime/issues /25885 , https://github.com/dotnet/runtime/issues/27285

如果您需要使用 GSSAPI,请尝试在容器中安装“gss-ntlmssp”。

或者,如果您的服务器接受其他身份验证类型,请使用另一种身份验证类型,例如 NTLM:

var cred = new NetworkCredential(user, password, domain);
var cache = new CredentialCache();
cache.Add(host, 25, "NTLM", cred);
client.Credentials = cache;

推荐阅读