I am trying to send a mail using Net.Mail.
The error message that I get in the line
"nClient.Send(nMail)"
is:
"Could not send mail to all recipients."
I don't know where I did something wrong.
Does anybody see my mistake?
Thank you very much!
Dim sSubject As String = "Response to your order"
Dim sBody As String = "Dear Sir or Madame, here is your invoice."
Dim sTo As String = "customer@customers.com"
Dim sFrom As String = "office@mycompany.com"
Dim sFromFriendly As String = "My super nice office team"
Dim nAtt As Net.Mail.Attachment = New Net.Mail.Attachment("C:\somepdf.pdf")
Dim nMail As New Net.Mail.MailMessage(sFrom, sTo, sSubject, sBody)
With nMail
.IsBodyHtml = False
.Bcc.Add(sFrom) 'Send a BCC to myself
.From = New MailAddress(sFrom, sFromFriendly) 'Add my nice name moniker
.Attachments.Add(nAtt) 'Add the pdf file
End With
Dim nCred As New System.Net.NetworkCredential
With nCred
.UserName = "myusername"
.Password = "mypassword"
End With
Dim nClient As New SmtpClient()
With nClient
.Host = "mywebhost"
.Port = 587
.UseDefaultCredentials = False
.Credentials = nCred
End With
nClient.Send(nMail)
nMail.Dispose()