简体   繁体   中英

How to check if the mail has been sent successfully

I am developing an Asp.Net application, where I am sending a mail to the user's email address, if he forgets the password.

I want to check if the mail has been sent sucessfully or not. Is there any method to know that for sure.

EDIT

In case if an email id does'nt exists, then would I detect a failure.

如果您的SmtpMail.Send(message)方法没有返回错误,则表示该电子邮件已发送到SMTP服务器,那么您不在您的管辖范围内,这就是您可以知道的距离。

如果你正在使用System.Net.Mail试试

message.DeliveryNotificationOptions = System.Net.Mail.DeliveryNotificationOptions.OnSuccess;

Put the .Send(msg) method in a try catch block, and catch SmtpFailedRecipientException.

try
{
    mail.Send(msg);
}
catch (SmtpFailedRecipientException ex)
{
    // ex.FailedRecipient and ex.GetBaseException() should give you enough info.
}

According to spec :

S: 220 smtp.example.com ESMTP Postfix
C: HELO relay.example.org
S: 250 Hello relay.example.org, I am glad to meet you
C: MAIL FROM:<bob@example.org>
S: 250 Ok
C: RCPT TO:<alice@example.com>
S: 250 Ok
C: RCPT TO:<theboss@example.com>
S: 250 Ok
C: DATA
S: 354 End data with <CR><LF>.<CR><LF>
C: From: "Bob Example" <bob@example.org>
C: To: Alice Example <alice@example.com>
C: Cc: theboss@example.com
C: Date: Tue, 15 Jan 2008 16:02:43 -0500
C: Subject: Test message
C:
C: Hello Alice.
C: This is a test message with 5 header fields and 4 lines in the message body.
C: Your friend,
C: Bob
C: .
S: 250 Ok: queued as 12345
C: QUIT
S: 221 Bye
{The server closes the connection}

As soon as server says 250 Ok: queued as 12345 , you cannot know for sure if it had really sent an email or not, or whether it was delivered.

You can use the DeliveryNotificationOptions to receive a receipt.

If you have a MailMessage object named mail, do this:

mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;

不是。电子邮件(基于SMPT)是一种不可靠的传输协议,虽然有一些黑客可以检测到已经收到并阅读了电子邮件,例如通过在电子邮件中嵌入个性化图像URL并跟踪图像已经收件人的客户要求,没有绝对可靠的方式来满足您的要求。

The SmtpClient.Send method will raise an Exception if there's a problem sending. But beyond getting that message to the SMTP server, there's no way to know if it makes it to the destination from there.

I'am using gmail SMTP for sending mails with my program. A fake mail sent returns Ok even with SmtpFailedRecipientException trap.

But when I check with outlook my gmail recipient I see that mail was not sent with explanation. With a subject Delivery Status Notification (Failure)

My question is it possible to get this notificiation whitin the program.

I found this but it's not for POP

Notify C# Client, when SMTP Server receive a new Email

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM