Reputation: 714
I have a contact us page set up on my website and I would like to make it appear like it is coming from a different email address.
<mailSettings>
<smtp from="[email protected]">
<network host="smtp.gmail.com" enableSsl="true" port="587" userName="[email protected]" password="password" defaultCredentials="false" />
</smtp>
</mailSettings>
So I make my mail client and try and send the email
MailMessage message = new MailMessage();
message.To.Add(new MailAddress(ConfigurationManager.AppSettings["ContactEmailTo"]));
message.Subject = "Contact Request";
message.Body = body;
SmtpClient client = new SmtpClient();
client.Send(message);
However, when I receive the email, I receive it from the admin address.
Upvotes: 0
Views: 1907
Reputation: 3112
It looks like you're sending through GMail. Their SMTP server rewrites the FROM address. See for example this question.
If you want to use GMail, this answer suggests adding the FROM email in your account settings under:
Settings -> Accounts -> Send mail as -> Add another email address you own
The other option is to use a different SMTP server that allows you to set your FROM address.
Upvotes: 1
Reputation: 9513
Use one of the constructor overloads on MailAddress
to specify an address and display name like so:
MailAddress address = new MailAddress("[email protected]", "John Smith");
See: http://msdn.microsoft.com/en-us/library/1s17zfkf%28v=vs.110%29.aspx for more info.
Upvotes: 1