I am using VB.net.
when i want to send an email with
Dim result As ISendMessageResult
result = smtp.SendMessage(email)
and for example because of a wrong emailadress, sending fails.
The returnvalue is NOTHING instead of a regular value.
and because of NOTHING, i can't handle any Errors because i don't get any
Values back.
How can i detect what has been the reason why sending failt.
Please help
Here is my extracted code:
Dim lngBytesSent As Long, ResponseText As String
', I As Integer, wert As String, response As SmtpResponse
builder.LoadHtml("MSG-Filename")
builder.Subject = "Test"
builder.From.Add(New MailBox("Sender@domain.de", "Sender@domain.de"))
builder.[To].Add(New MailBox("rec1@domain.de", "rec1@domain.de"))
builder.[To].Add(New MailBox("rec2@domain.de", "rec2@domainxxx.de"))
Dim email As IMail = builder.Create()
Using smtp As New Smtp()
Try
smtp.AllowPartialSending = True
smtp.Connect(mSMTPServerName, mSMTPServerPort)
' or ConnectSSL for SSL
If mSMTPAccountName = "" Then
Else
smtp.UseBestLogin(mSMTPAccountName, mSMTPAuthPWD)
End If
Catch ex As Exception
smtp.Close()
Exit Sub
End Try
Dim result As ISendMessageResult
Try
result = smtp.SendMessage(email)
'with a wrong reciepient an error is thrown
If result.Status = 0 Then
MsgBox("result.Status = 0")
Else
If result.Status = 1 Then
'Partial success status: message was succesfully
'sent to some, but not to all receipients
If result.FromRejected Then
MsgBox("result.FromRejected")
Else
If result.RejectedRecipients.Count <> 0 Then
MsgBox("result.RejectedRecipients.Count <> 0")
Else
SendStatus = 4 'Socket closed
ResponseText = Get_ResponseText(result.AllResponses)
End If
End If
Else 'keine email ging raus, Failure status: message sending failed
End If
End If
Catch e As SmtpResponseException
'error handling never reaches this section WHY !!!!
MsgBox(e.Response) '
If IsNothing(result) Then
MsgBox("result.Status = Nothing")
Else
If result.Status = 2 Then
'keine email ging raus, Failure status: message sending failed
MsgBox("result.Status = 2")
Else
MsgBox("result.Status = 1")
End If
End If
Catch ex As Exception
MsgBox(ex.Message)
If IsNothing(result) Then
MsgBox("result.Status = Nothing")
Else
If result.Status = 2 Then
'keine email ging raus, Failure status: message sending failed
MsgBox("result.Status = 2")
Else
MsgBox("result.Status = 1")
End If
End If
End Try
smtp.Close()
End Using
with a wrong receipient i always end up in the 'Catch ex As Exception' section. and result is NOTHING.
Thank you for your immediate response.