sta*_*son 10
如果你正在使用System.Net.Mail试试
message.DeliveryNotificationOptions = System.Net.Mail.DeliveryNotificationOptions.OnSuccess;
Run Code Online (Sandbox Code Playgroud)
将.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)
根据规格:
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,您无法确定它是否真的发送过电子邮件,或者是否已发送.
您可以使用DeliveryNotificationOptions接收收据。
如果您有一个MailMessage名为mail 的对象,请执行以下操作:
mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
62018 次 |
| 最近记录: |