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

Vai*_*ain 23 .net c# asp.net smtp

我正在开发一个Asp.Net应用程序,如果他忘记了密码,我将向用户的电子邮件地址发送邮件.

我想检查邮件是否已成功发送.有没有什么方法可以肯定地知道.

编辑

如果电子邮件ID不存在,那么我会检测到失败.

Fra*_*ino 23

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


sta*_*son 10

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

message.DeliveryNotificationOptions = System.Net.Mail.DeliveryNotificationOptions.OnSuccess;
Run Code Online (Sandbox Code Playgroud)

  • 那假设是做什么的?它只是一个设置,没有解释. (23认同)

Bra*_*don 8

将.Send(msg)方法放在try catch块中,并捕获SmtpFailedRecipientException.

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


Ant*_*lev 6

根据规格:

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}
Run Code Online (Sandbox Code Playgroud)

一旦服务器说250 Ok: queued as 12345,您无法确定它是否真的发送过电子邮件,或者是否已发送.


Aar*_*ron 5

您可以使用DeliveryNotificationOptions接收收据。

如果您有一个MailMessage名为mail 的对象,请执行以下操作:

mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
Run Code Online (Sandbox Code Playgroud)