c# – SmtpClient.Send不适用于linux环境

以下代码,在.net core 2环境中编写,适用于 Windows环境,但不适用于 Linux环境.

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);

例外:发送邮件失败.

InnerExcepiton:

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,Object sessionCookie,ChannelBinding channelBindingToken)
   at System.Net.Mail.SmtpConnection.SetContextAndTryAuthenticate(ISmtpAuthenticationModule module,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环境下工作?

解决方法

我认为这是一个代码错误,因为我有错误,但事实并非如此.当我在邮件服务器端给出中继权限时,我的问题就解决了.我认为它是在Windows环境中自动执行此操作.

相关文章

目录简介使用JS互操作使用ClipLazor库创建项目使用方法简单测...
目录简介快速入门安装 NuGet 包实体类User数据库类DbFactory...
本文实现一个简单的配置类,原理比较简单,适用于一些小型项...
C#中Description特性主要用于枚举和属性,方法比较简单,记录...
[TOC] # 原理简介 本文参考[C#/WPF/WinForm/程序实现软件开机...
目录简介获取 HTML 文档解析 HTML 文档测试补充:使用 CSS 选...