Reputation: 2026
I have a contact form on my website. In the past I sent the mails using my admin gmail account (with gmail smtp). Now I have to switch to a professional account made on outlook. Problem is that it now seems impossible to spoof another address into the reply header. If I reply on the mail it always get send to "[email protected]" instead of the address filled in on the contact form.
This is the code that used to work in the past. Is there any way to make this code work again?
try
{
var message = new MailMessage();
message.To.Add(new MailAddress("[email protected]"));
message.From = new MailAddress(from);
message.ReplyToList.Clear();
message.ReplyToList.Add(new MailAddress(from));
message.Subject = subject;
message.Body = body;
message.IsBodyHtml = true;
var client = new SmtpClient("smtp-mail.outlook.com", 587)
{
EnableSsl = true,
UseDefaultCredentials = false,
Credentials = new NetworkCredential("[email protected]", "xxxxx")
};
client.Send(message);
}
catch (Exception e)
{
return false;
}
return true;
Upvotes: 0
Views: 1092
Reputation: 5776
Just use a string here:
message.ReplyToList.Add(new MailAddress(from));
Change the above code to read:
message.ReplyToList.Add(from);
MailAddressCollection.Add(...) takes a string as an argument, not a MailMessage. This is probably why it is ignoring it.
https://msdn.microsoft.com/en-us/library/ms144695(v=vs.110).aspx
Upvotes: 0