Email Delivery Message in Asp.net(how to check whe

2020-06-27 10:57发布

protected void btnSend_Click(object sender, EventArgs e)
{
    string mFrom = "xxx.com";
    string mTo = "yyy.com";
   string msub="TESTSUBJECT";
    string mMsg="TEST msg";
    string mCc = "Test cc";

    // User credential used for sending mail
    string EmailSender = "xxx.com";
    string EmailSenderPasswd = "zzz";
    System.Net.NetworkCredential myCachet = new System.Net.NetworkCredential(EmailSender, EmailSenderPasswd);
    SmtpClient smtp = new SmtpClient("smtpout.secureserver.net", 12234);
    smtp.Credentials = myCachet;

    MailMessage message = new MailMessage(mFrom.ToString(), mTo.ToString());
    message.Subject = msub.ToString();
    message.Body = mMsg.ToString();
    message.IsBodyHtml = true;
    if (mCc.Trim() != String.Empty)
    {
        message.CC.Add(new MailAddress(mCc.ToString()));
    }
    smtp.Send(message);
    message.Dispose();
}

If i pass the wrong password, smtp.send(message) method returns "Message failure". But if im pass wrong email address it returns as success message as "Message Success" and it does not deliver any exception even i tried try and catch exception. How to know that message is delivered successfully? If that message is not delivered successfully means it should throws a undelivered message like gmail(Message delivery failed). Help me.

1条回答
对你真心纯属浪费
2楼-- · 2020-06-27 11:27

On Adding:

message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;

Delivery Notification Mail works. But i have to store undelivered mail details in db. How to track that undelivered mails(By Username).

查看更多
登录 后发表回答