Я не думаю, что вы можете поймать эти исключения в своем коде, письма, которые не отправляются, вы захотите проверить на сервере SMTP, должна быть папка почты в inetpub
\\ServerName\c$\Inetpub\mailroot
Внутри этой папки вы должны найти папку с именем: BadMail and Drop, пожалуйста, посмотрите на их содержимое. Ваш VB-код не имеет доступа к действительному адресу электронной почты, он может только попытаться отправить SMTP-сообщение электронной почты, в случае неудачи приложение SMTP обрабатывает это.
За ваш комментарий:
Imports System.Net.Mail
Imports System.Threading
Imports System.Web.Configuration
''' <summary>
''' Provides a method for sending email.
''' </summary>
Public NotInheritable Class Email
Private Sub New()
End Sub
''' <summary>
''' Constructs and sends an email message.
''' </summary>
''' <param name="fromName">The display name of the person the email is from.</param>
''' <param name="fromEmail">The email address of the person the email is from.</param>
''' <param name="subject">The subject of the email.</param>
''' <param name="body">The body of the email.</param>
Public Shared Sub Send(fromName As String, fromEmail As String, subject As String, body As String)
Dim message As New MailMessage() With { _
Key .IsBodyHtml = False, _
Key .From = New MailAddress(fromEmail, fromName), _
Key .Subject = subject, _
Key .Body = body _
}
message.[To].Add(WebConfigurationManager.AppSettings("mailToAddresses"))
Dim originalRecipientCount As Integer = message.[To].Count
Dim failOnAnyAddress As Boolean = Convert.ToBoolean(WebConfigurationManager.AppSettings("failOnAnyAddress"))
Try
Send(message)
Catch generatedExceptionName As SmtpFailedRecipientException
If message.[To].Count = originalRecipientCount Then
' all recipients failed
Throw
End If
If failOnAnyAddress Then
' some (not ALL) recipients failed
Throw
End If
End Try
End Sub
Private Shared Sub Send(message As MailMessage)
Dim client As New SmtpClient()
Try
client.Send(message)
Catch ex As SmtpFailedRecipientsException
' multiple fail
message.[To].Clear()
For Each sfrEx As SmtpFailedRecipientException In ex.InnerExceptions
CheckStatusAndReaddress(message, sfrEx)
Next
If message.[To].Count > 0 Then
' wait 5 seconds, try a second time
Thread.Sleep(5000)
client.Send(message)
Else
Throw
End If
Catch ex As SmtpFailedRecipientException
' single fail
message.[To].Clear()
CheckStatusAndReaddress(message, ex)
If message.[To].Count > 0 Then
' wait 5 seconds, try a second time
Thread.Sleep(5000)
client.Send(message)
Else
Throw
End If
Finally
message.Dispose()
End Try
End Sub
Private Shared Sub CheckStatusAndReaddress(message As MailMessage, exception As SmtpFailedRecipientException)
Dim statusCode As SmtpStatusCode = exception.StatusCode
If statusCode = SmtpStatusCode.MailboxBusy OrElse statusCode = SmtpStatusCode.MailboxUnavailable OrElse statusCode = SmtpStatusCode.TransactionFailed Then
message.[To].Add(exception.FailedRecipient)
End If
End Sub
End Class
Конвертировать любой код из C # в vb.net: http://www.developerfusion.com/tools/convert/csharp-to-vb/