[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 448
  • Last Modified:

MailMessage: Send email through a domain with an email address with a different domain

In Outlook, and most email programs, you can send an email message with the address user@domain.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("user@otherdomain.com", "password"), the message fails with the error "Mailbox unavailable. The server response was: Verification failed for <automated@domain.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")
      With msg
            .IsBodyHtml = True
            .From = New MailAddress("automated@domain.com")
            .To.Add(New MailAddress("Some Person <someperson@somewhere.com>")
            .Subject = "Form Confirmation"
            .Body = "test"
            .Priority = MailPriority.High
            .Headers.Add("Priority", "High")
            .Headers.Add("X-Priority", "1")
            .Headers.Add("X-MSMail-Priority", "High")
      End With
      smtp.Credentials = New System.Net.NetworkCredential("user@otherdomain.com", "password")
      smtp.Send(msg)

Thanks.
0
rbichon
Asked:
rbichon
  • 3
  • 3
1 Solution
 
vbturboCommented:
try check out these links

http://www.systemnetmail.com/'net 2.0

http://www.systemwebmail.com/'net 1.1

vbturbo
0
 
rbichonAuthor Commented:
I don't give points to those who take blind guesses. Your links, though related to sending messages, did not even broach on my problem. Please, if you don't know the answer then don't post here.
0
 
vbturboCommented:
Hi

Well im not in it for the blind guesses !!! neighter cheap points.
Just thouhgt you might have forgotten to pass on a username in your "smtp.Credentials"

And since no one else is replying this question ill give it a shot though.

Are you trying to send message as a member of domain or group member through IIS ?
Or are you useing win2k server ,msexchange? THIS IS missing in your problem description

I have answered a similar question a while ago and i recommend you, to try and see if it fit's your problem,regarding sending mails from different domains


http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21973576.html

vbturbo
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
rbichonAuthor Commented:
My question explains my problem precisely. My code very clearly shows that I am passing credentials to the smtp server.
0
 
vbturboCommented:
READ this

http://groups.google.dk/group/microsoft.public.inetserver.iis.smtp_nntp/browse_thread/thread/38d32aa852edba4e/137404d3072ff630%23137404d3072ff630

I dont want to speculate in if you are useing smarthost ....ect(though as i stateted ! THIS IS missing in your problem description)

as i see it ! you are a member/user of a [main domain ("otherdomain.com")]

     your code
--------------------------------------------------------------
     smtp = New SmtpClient("otherdomain.com")
     smtp.Credentials = New System.Net.NetworkCredential("user@otherdomain.com", "password")
--------------------------------------------------------------

Your Question
The server response was: Verification failed for <automated@domain.com>"

Yeah well ("automated@domain.com") does not have any Credentials when the smtp.server is authenticating the sender   (.From)
The Credentials that you are assigning to ("user@otherdomain.com")  is missing in the validation of ("automated@domain.com")

         .From = New MailAddress("automated@domain.com")
          .To.Add(New MailAddress("Some Person <someperson@somewhere.com>")
          .Subject = "Form Confirmation"
          .Body = "test"
          .Priority = MailPriority.High
          .Headers.Add("Priority", "High")
          .Headers.Add("X-Priority", "1")
          .Headers.Add("X-MSMail-Priority", "High")
     End With
     smtp.Credentials = New System.Net.NetworkCredential("user@otherdomain.com", "password")

So you could for example try alter the .From = New MailAddress("automated@domain.com")  TO .From = New MailAddress("user@otherdomain.com")

That way the NetworkCredential should  no longer be an issue.

One question ! is this for a mail robot/spam ?

vbturbo
0
 
rbichonAuthor Commented:
I found out that certain mail servers don't allow a user, even when authenticated, to use an incorrect from address when sending. It is most likely to prevent spam which would be great if it were done everywhere. No, I am not sending spam. When a user contacts us from our site http://www.domain.com, we send an autoreply from automated@domain.com. Unfortunately, we also have several other sites and want the autoresponder to reflect those domain names, i.e. automated@otherdomain.com. And we didn't want to send the replies out on multiple mail servers so we tried to consolidate them to one mail server. Thanks for you help.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now