Solved

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

Posted on 2006-11-09
6
416 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 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

11 Experts available now in Live!

Get 1:1 Help Now