I am trying to send mail using SmtpClient() within my Winforms VB.Net program
Here is the code:
Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
Dim _Attachment As String
If gcloUtilities.GetUser(mHostName, mEMailUser, mEMailPassword, mFromEMail) = False Then
Exit Sub
End If
SmtpServer.Credentials = New Net.NetworkCredential(mEMailUser, mEMailPassword)
SmtpServer.Port = 587
SmtpServer.Host = mHostName
mail = New MailMessage()
mail.From = New MailAddress(mFromEMail)
mail.To.Add(mfrmSendAnEmail.txtTo.Text)
mail.Subject = mfrmSendAnEmail.txtSubject.Text
_Attachment = mDirectory & "\" & gcloGlobals.DocumentName & ".pdf"
Dim oAttch As Attachment = New Attachment(_Attachment)
mail.Attachments.Add(oAttch)
mail.Body = mfrmSendAnEmail.txtBody.Text
SmtpServer.Send(mail)
For Host Name I using mail dot metaprosystems dot com, the user name and password are the user name and password I use to log into my mail server. This work when the To address is within my domain. For example bob at-sign metaprosystems.com. It does not work when I send to an email outside my domain. I get this exception in my catch block:
“Mailbox name not allowed. The server response was: sorry, that domain isn’t in my list of allowed rcpthosts (#5.7.1)”
Whether I include an attachment or not doesn’t matter.
I believe the problem is with my web hosting company, but so far they haven’t come up with a solution. I need so advice as to what to tell them to do to fix this. Alternatively, If I could fix it on my end that would be great.
Thanks for all the suggestions, my host company gave me the answer. I need to use bob at-sign metaprosystems.com instead of just bob as the user. The correct email user name may depend on your host company.