MailMessage: Send email through a domain with an email address with a different domain
Posted on 2006-11-09
In Outlook, and most email programs, you can send an email message with the address email@example.com through otherdomain.com so long as you login to the smtp server with the correct credentials. I am having trouble doing this with MailMessage. Even though I have smtp.Credentials = New System.Net.NetworkCredential("firstname.lastname@example.org", "password"), the message fails with the error "Mailbox unavailable. The server response was: Verification failed for <email@example.com>". Why isn't it trying to authenticate with the correct account? Can anyone tell me what I am doing wrong? Here is the code:
Dim msg As New MailMessage
Dim smtp As New SmtpClient
msg = New MailMessage
smtp = New SmtpClient("otherdomain.com")
.IsBodyHtml = True
.From = New MailAddress("firstname.lastname@example.org")
.To.Add(New MailAddress("Some Person <email@example.com>")
.Subject = "Form Confirmation"
.Body = "test"
.Priority = MailPriority.High
smtp.Credentials = New System.Net.NetworkCredential("firstname.lastname@example.org", "password")