2017-10-09 13 views
3

.net core 2環境で書かれた次のコードは、the windows environmentで動作しますが、the linux environmentでは動作しません。Linux環境でSmtpClient.Sendが動作しない

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

例外: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

これはコンソールアプリケーションです。 なぜLinux環境で動作していないのですか?

+0

SMTPサーバーが認証を要求している可能性があります。 'telnet 10.99.99.10 25'を試して、SMTPコマンドを使ってテスト電子メールを送信してみてください。 http://www.samlogic.net/articles/smtp-commands-reference.htm –

+0

@SameerNaik Telnetが動作しています。(10.99.99.10 25) – Cer

+0

0x80004005エラーコードの原因は、インストールが破損しているようです。私は.netコアを再インストールしようとします。 https://support.microsoft.com/en-gb/help/914232/you-may-receive-error-code-0x80004005-or-other-error-codes-when-you-tr –

答えて

0

エラーのためにコードエラーと思っていましたが、そうではありませんでした。私がメールサーバ側でrelay authorityを与えたとき、私の問題は解決されました。私はそれがWindows環境でこれを自動的に行っていると思います。

+0

メールサーバ上のリレー権限はなんですか? –

関連する問題