0

私はMailkit/MimekitEasymail を初めて使用し、Easymail から移行中です。以下のコードは、次のエラーメッセージを表示します

Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

これは、Try Catch ステートメントを使用した場合です。Try Catch を削除すると、次のような出力が得られます。

2.0.0 Ok: queued as 3rdP7Y5ZrzzJp60

私のSMTPサーバーは問題ないので、これは予想される出力です。なぜこれが起こるのでしょうか?サーバーが応答しないエラーをキャッチしようとしているだけです

string ReturnEmail = "returnpath@xxxxxxx";
string ReturnName  = "Return xxxxxxx";
string FromEmail   = "xxxxxxx@xxxxxxx.com";
string FromName    = "xxxxxxx";
string SenderEmail = "xxxxxxx@xxxxxxx.com";
string SenderName  = "xxxxxxx";      
string TextBody    = @"Text Body";
string HtmlBody = string.Format(@"HTML Body");
string Subject = "Retrouvez-nous à la e à l’occasion de la Coupe du Monde de Combiné Nordique";
string ToName = "XXX";
string ToEmail = "XX@XXX.com";
string MailServer = "XX.XXX.XX.XXX";
int Result = 0;
var message = new MimeMessage();

MailboxAddress RecepientAddress = new MailboxAddress(ToName, ToEmail);
message.From.Add(new MailboxAddress(FromName, FromEmail));

var builder = new BodyBuilder();

builder.TextBody = TextBody;
builder.HtmlBody = HtmlBody;

List<MailboxAddress> To = new List<MailboxAddress>();
To.Add(RecepientAddress);

message.Subject = Subject;
message.Body = builder.ToMessageBody();
message.Sender = new MailboxAddress(SenderName, SenderEmail);  // Sender Address
message.To.Add (RecepientAddress);    
var client = new SmtpClient( new ProtocolLogger("smtp.txt") ); // logging SMTP connections
client.Timeout = 20;

// client.Connect(MailServer, 25);
try
{
    client.Connect(MailServer, 25);
}
catch (SmtpCommandException ex)
{
    Console.WriteLine("Error trying to connect: {0}", ex.Message);
    Console.WriteLine("\tStatusCode: {0}", ex.StatusCode);               
}
catch (SmtpProtocolException ex)
{
    Console.WriteLine("Protocol error while trying to connect: {0}", ex.Message);             
}
catch (Exception ex)
{
   Console.WriteLine(ex.Message);             
}
4

1 に答える 1

1

次の行を削除します。

client.Timeout = 20;
于 2016-06-27T20:53:15.433 に答える