Solved

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

Posted on 2006-11-09
6
418 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Word Template Mail merge with vb.net 4 59
System32Int Error 8 57
Code enhancement 5 23
Help with highlighting rows based on identical values in multiple columns 1 35
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…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

896 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now