Solved

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

Posted on 2006-11-09
6
419 Views
Last Modified: 2008-02-01
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
Comment
Question by:rbichon
  • 3
  • 3
6 Comments
 
LVL 18

Accepted Solution

by:
vbturbo earned 250 total points
ID: 17910924
try check out these links

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

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

vbturbo
0
 
LVL 1

Author Comment

by:rbichon
ID: 17914167
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
 
LVL 18

Expert Comment

by:vbturbo
ID: 17928468
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
ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

 
LVL 1

Author Comment

by:rbichon
ID: 17935339
My question explains my problem precisely. My code very clearly shows that I am passing credentials to the smtp server.
0
 
LVL 18

Expert Comment

by:vbturbo
ID: 17936601
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
 
LVL 1

Author Comment

by:rbichon
ID: 18084779
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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question