Question

I have this code

 var mail = new MailMessage(
                "from@from.com",
                "to@to.com",
                "subject",
                "body");
 mail.ReplyToList.Add(new MailAddress("from@from.com"));

 var client = new SmtpClient();

 client.Send(mail);

In my web.config file I have

<system.net>
    <mailSettings>
      <smtp from="no-reply@no-reply.com">
        <network host="smtp.live.com" password="mypassword" port="587" userName="myemailaddress@hotmail.com" enableSsl="true" />
      </smtp>
    </mailSettings>
  </system.net>

The problem is this: The to address of the email that gets sent to to@to.com is not from@from.com but instead is myemailaddress@hotmail.com. When I hit reply to the email address then because I have this line:

mail.ReplyToList.Add(new MailAddress("from@from.com"));

The reply to email address does get set to from@from.com.

What I want is:

  1. The reply to email address to be from@from.com (as it is now)
  2. The to email address to be from@from.com as well.

Right now, it seems to anyone receiving the email that the email has come from myemailaddress@hotmail.com. I thought that the configuration in the web.config that I added was only for authenticating against the smtp.live.com mail server and that the email address wouldn't be used in the email being sent.

What am I doing wrong?

Was it helpful?

Solution

Here is a guide you can use to set up your own SMTP server. Assuming you own "from.com" this will resolve your issue.

Have a look at the MSDN Documentation

If you need to send email from many different domains you can configure virtual SMTP servers for each domain. Have a look at this article.

If you do not own the domains that you are attempting to send mail from then it will look like you are spoofing the sender address.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top