简体   繁体   English

如何检查邮件是否已成功发送

[英]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. 我正在开发一个Asp.Net应用程序,如果他忘记了密码,我将向用户的电子邮件地址发送邮件。

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. 如果电子邮件ID不存在,那么我会检测到失败。

如果您的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. 将.Send(msg)方法放在try 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. 一旦服务器说250 Ok: queued as 12345 ,您就无法确定它是否真的发送过电子邮件,或者是否已发送。

You can use the DeliveryNotificationOptions to receive a receipt. 您可以使用DeliveryNotificationOptions来接收收据。

If you have a MailMessage object named mail, do this: 如果您有一个名为mail的MailMessage对象,请执行以下操作:

mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;

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

The SmtpClient.Send method will raise an Exception if there's a problem sending. 如果发送问题, SmtpClient.Send方法将引发异常。 But beyond getting that message to the SMTP server, there's no way to know if it makes it to the destination from there. 但除了将该消息发送到SMTP服务器之外,没有办法知道它是否从那里到达目的地。

I'am using gmail SMTP for sending mails with my program. 我正在使用gmail SMTP与我的程序发送邮件。 A fake mail sent returns Ok even with SmtpFailedRecipientException trap. 即使使用SmtpFailedRecipientException陷阱,发送的假邮件也会返回Ok。

But when I check with outlook my gmail recipient I see that mail was not sent with explanation. 但是,当我查看outlook我的Gmail收件人时,我发现邮件没有发送解释。 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 我发现了这个,但它不适用于POP

Notify C# Client, when SMTP Server receive a new Email 当SMTP服务器收到新电子邮件时,通知C#客户端

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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