【问题标题】:SmtpClient.Send not working on linux environmentSmtpClient.Send 在 linux 环境下不起作用
【发布时间】:2017-10-09 06:09:32
【问题描述】:

以下代码在.net core 2 环境中编写,在the windows environment 中有效,但在the linux environment 中无效。

string host = "10.99.99.10";
int port = 25;
string userName = "user@user.com";
string password = "password";
string from = userName;

var client = new SmtpClient
{
    Host = host,
    Port = port,
    EnableSsl = false,
    DeliveryMethod = SmtpDeliveryMethod.Network,
    UseDefaultCredentials = false,
    Credentials = new NetworkCredential(userName, password)
};

MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress(from);
mailMessage.To.Add(userName);
mailMessage.Body = "This is test mail.";
mailMessage.Subject = "Testing";                
client.Send(mailMessage);

例外:Failure sending mail.

内部异常:

System.ComponentModel.Win32Exception (0x80004005): GSSAPI operation failed with error - An invalid status code was supplied (Unknown error).
   at System.Net.Security.NegotiateStreamPal.AcquireCredentialsHandle(String package, Boolean isServer, NetworkCredential credential)
   at System.Net.NTAuthentication.Initialize(Boolean isServer, String package, NetworkCredential credential, String spn, ContextFlagsPal requestedContextFlags, ChannelBinding channelBinding)
   at System.Net.Mail.SmtpNtlmAuthenticationModule.Authenticate(String challenge, NetworkCredential credential, Object sessionCookie, String spn, ChannelBinding channelBindingToken)
   at System.Net.Mail.SmtpConnection.SetContextAndTryAuthenticate(ISmtpAuthenticationModule module, NetworkCredential credential, ContextAwareResult context)
   at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port)
   at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port)
   at System.Net.Mail.SmtpClient.GetConnection()
   at System.Net.Mail.SmtpClient.Send(MailMessage message)

堆栈跟踪:

at System.Net.Mail.SmtpClient.Send(MailMessage message)
   at MyProject.Helper.Utils.SendMail() in C:\Test\MyProject\MyProject.Helper\Utils.cs:line 146

Linux:Ubuntu 16.04.3 LTS

这是一个控制台应用程序。 为什么在linux环境下不行?

【问题讨论】:

标签: c# linux asp.net-core .net-core asp.net-core-2.0


【解决方案1】:

由于我遇到的错误,我认为这是一个代码错误,但事实并非如此。当我在邮件服务器端提供relay authority 时,我的问题就解决了。我认为它是在 Windows 环境中自动执行此操作的。

编辑:在接收连接器/Exchange 服务器中添加 IP 地址并允许匿名用户

【讨论】:

  • 邮件服务器的中继权限到底是什么?
  • @danieltheman 我认为它发送邮件时不会检查匿名用户信息。
  • 也检查this answer
猜你喜欢
  • 1970-01-01
  • 2011-09-28
  • 1970-01-01
  • 2023-04-01
  • 2018-12-14
  • 2015-01-09
  • 2018-05-01
  • 2012-02-23
  • 1970-01-01
相关资源
最近更新 更多