I have an event for a button, that simply emails me whatever the user entered. I get the message fine....subject....message. But the from email part is just showing from myself (same as the one it is going to)
How to do I have it show from whatever email address they entered?
I'm using gmail smtp to a gmail account that I have set up.
MailMessage has 4 parameters (from, to, subject, body)
txtEmail.Text does hold their email address correctly.
protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)
{
this.toEmail = "[email protected]";
this.subject = txtSubject.Text;
this.fromEmail = txtEmail.Text;
this.comment = txtComment.Text;
message = new MailMessage(fromEmail, toEmail, subject, comment);
smtp.Send(message);
message.Dispose();
}
I tried the suggestion like below with something like this... and still showing from myself.
message = new MailMessage(ReplyToList[0].toString(), toEmail, subject, comment);
I even tried doing it this way and still shows from myself. I even stepped through the code to make sure, it was holding different email addresses and it is.
protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)
{
this.subject = txtSubject.Text;
this.comment = txtComment.Text;
to = new MailAddress("[email protected]");
from = new MailAddress(txtEmail.Text);
MailMessage message = new MailMessage(from, to);
message.Subject = txtSubject.Text;
message.Body = txtComment.Text;
message.Headers.Add("Reply-To", txtEmail.Text);
smtp.Send(message);
message.Dispose();
}
In the code I just call SmtpClient client = new SmtpClient();
Then in my web.config I have
<mailSettings>
<smtp from="bob">
<network host="smtp.gmail.com" port="587" userName="myemail" password="mypassword" enableSsl="true"/>
</smtp>
</mailSettings>
any help?
As James Manning has suggested an easy way of doing this would be to set a reply-to header on the email before sending as follows: