2010-02-26 165 views
15

我正在开发一个Asp.Net应用程序,如果他发送邮件给用户的电子邮件地址,如果他忘记了密码。如何检查邮件是否已成功发送

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

编辑

在情况下,如果一个电子邮件ID一点儿也不存在,那么我会检测到故障。

回答

15

如果您的SmtpMail.Send(message)方法没有返回任何错误,这意味着电子邮件已发送到SMTP服务器,那么您已超出您的管辖范围,即您可以知道多远。

6

根据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:<[email protected]> 
S: 250 Ok 
C: RCPT TO:<[email protected]> 
S: 250 Ok 
C: RCPT TO:<[email protected]> 
S: 250 Ok 
C: DATA 
S: 354 End data with <CR><LF>.<CR><LF> 
C: From: "Bob Example" <[email protected]> 
C: To: Alice Example <[email protected]> 
C: Cc: [email protected] 
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} 

只要服务器说250 Ok: queued as 12345,你可以不知道,如果它真的发送了一封电子邮件与否,或者是否被交付。

+0

你怎么竟跟踪/检查?有没有一个工具来跟踪smtp通信?基于Linux? – 2012-04-20 12:45:37

4

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

4

如果发送出现问题,SmtpClient.Send方法将引发异常。但除了将该消息发送到SMTP服务器之外,无法知道它是否从目标站点到达目的地。

7

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

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

如果您使用System.Net.Mail尝试

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

Aaaah在16秒内击败了我:( – Aaron 2010-02-26 15:08:51

+14

那该怎么办?这只是一个设置,没有解释。 – codingbiz 2013-04-14 15:07:54

4

可以使用DeliveryNotificationOptions收到收据。

如果你有一个名为邮件MailMessage对象,这样做:

mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess; 
相关问题