Der folgende Code, der in der .net core 2
-Umgebung geschrieben wurde, funktioniert in the windows environment
, aber nicht in the linux environment
.SmtpClient.Send funktioniert nicht unter Linux-Umgebung
string host = "10.99.99.10";
int port = 25;
string userName = "[email protected]";
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);
Ausnahme: Failure sending mail.
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, 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)
Stacktrace:
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
Dies ist eine Konsolenanwendung. Warum funktioniert nicht in Linux-Umgebung?
Ihr SMTP-Server erfordert möglicherweise eine Authentifizierung. Versuchen Sie 'telnet 10.99.99.10 25' und versuchen Sie, eine Test-E-Mail mit SMTP-Befehlen zu senden. http://www.samlogic.net/articles/smtp-commands-reference.htm –
@SameerNaik Telnet funktioniert. (10.99.99.10 25) – Cer
Die Ursache des 0x80004005 Fehlercodes scheint eine beschädigte Installation zu sein. Ich würde versuchen, .net-Core neu zu installieren. https://support.microsoft.com/en-gb/help/914232/you-may-receive-error-code-0x80004005-oder-other-error-codes-when-you-tr –