邮件发送在Asp.net中的消息(如何检查邮件是否发送?)
本文关键字:是否 何检查 检查 Asp net 消息 | 更新日期: 2023-09-27 18:15:23
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();
}
如果我传递了错误的密码,smtp.send(message)方法返回" message failure"。但是,如果我传递错误的电子邮件地址,它返回作为成功消息为"消息成功",它不提供任何异常,即使我尝试尝试捕获异常。如何知道消息已成功传递?如果该消息没有成功交付意味着它应该抛出一个未交付的邮件,如gmail(邮件交付失败)。帮助我。
On addition:
message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
发送通知邮件有效。但是我必须在数据库中存储未投递邮件的详细信息。如何跟踪未投递的邮件(通过用户名)