Reputation: 46740
I have this code
var mail = new MailMessage(
"[email protected]",
"[email protected]",
"subject",
"body");
mail.ReplyToList.Add(new MailAddress("[email protected]"));
var client = new SmtpClient();
client.Send(mail);
In my web.config file I have
<system.net>
<mailSettings>
<smtp from="[email protected]">
<network host="smtp.live.com" password="mypassword" port="587" userName="[email protected]" enableSsl="true" />
</smtp>
</mailSettings>
</system.net>
The problem is this: The to address of the email that gets sent to [email protected] is not [email protected] but instead is [email protected]. When I hit reply to the email address then because I have this line:
mail.ReplyToList.Add(new MailAddress("[email protected]"));
The reply to email address does get set to [email protected].
What I want is:
Right now, it seems to anyone receiving the email that the email has come from [email protected]. 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?
Upvotes: 1
Views: 417
Reputation: 4434
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.
Upvotes: 1