0

イントロ:サイトへの登録が成功すると、ウェルカム/確認メールを送信するコードをサポートしています。

SMTPクライアントは、送信が完了する前にタイムアウトします。運用部門によると、正しいクレデンシャルとSMTPサーバーのIPアドレスを使用しています。

私がやりたいのは、ハンドシェイク、接続、送信などのイベントにフックして、プロセスがタイムアウトする理由を正確に把握できるようにすることです。そのページでServer.ScriptTimeOutを500秒に設定したので、サーバーがビジー状態の問題になるだけではありません。

私の質問はこれです:このプロセス中にどのようなイベントを処理できますか。SMTPClientで公開されているのはSendCompletedだけです。しかし、もっと低レベルのものにアクセスする方法があるに違いないと思いますか?

参考までに、コードは次のとおりです。

//Create and send email
MailMessage mm = new MailMessage();
try
{
    mm.From = new MailAddress("admin@site.com");
    mm.To.Add(new MailAddress(Recipient));
    mm.Subject = Subject;
    mm.Body = MailBody;
    mm.IsBodyHtml = true;

    var c = new NetworkCredential("admin@site.com", "YeOlePassword");

    SmtpClient smtp = new SmtpClient("127.0.0.1");//not really, just hiding our SMTP IP from StackOverflow

    smtp.UseDefaultCredentials = false;
    smtp.Credentials = c;
    smtp.Send(mm);

}
catch (Exception x)
{
    DateTime CurrentDateTime = DateTime.Now;
    String appDateTime = CurrentDateTime.ToString();

    String transactionLogEntry = "To: " + Recipient + " " + appDateTime + " " + x.Message;
    StreamWriter streamwriter = new StreamWriter(File.Open(MapPath("~/TransactionLog.txt"), FileMode.Append, FileAccess.Write, FileShare.Write));

    //Append to file
    streamwriter.WriteLine(transactionLogEntry);
    //Close file
    streamwriter.Close();
}

ログに記録されるエラーは、指定された電子メールアドレスにメールを送信しているときにタイムアウトが発生したことです。

4

1 に答える 1

1

これを使用して、埋め込まれたSMTPメッセージを取り出します。

String transactionLogEntry = "To: " + Recipient + " " + appDateTime + " " + GetFullErrorMessage(x);

.
.
.

private string GetFullErrorMessage(Exception e)
    {
        string strErrorMessage = "";
        Exception excpCurrentException = e;

        while (excpCurrentException != null)
        {
            strErrorMessage += "\"" + excpCurrentException.Message + "\"";
            excpCurrentException = excpCurrentException.InnerException;
            if (excpCurrentException != null)
            {
                strErrorMessage += "->";
            }
        }

        strErrorMessage = strErrorMessage.Replace("\n", "");

        return strErrorMessage;
    }

私の経験では、あなたが説明していることから、それはISPまたはサーバー/WebホストによってブロックされているSMTPポートに関連しています。幸運を!

于 2013-01-22T08:55:54.930 に答える