c# - MailMessage ASP.NET Wrong from email? -
i have event button, emails me whatever user entered. message fine....subject....message. email part showing myself (same 1 going to)
how have show whatever email address entered?
i'm using gmail smtp gmail account have set up.
mailmessage has 4 parameters (from, to, subject, body)
txtemail.text hold email address correctly.
protected void wizard1_finishbuttonclick(object sender, wizardnavigationeventargs e) { this.toemail = "myemail@gmail.com"; 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 suggestion below this... , still showing myself.
message = new mailmessage(replytolist[0].tostring(), toemail, subject, comment);
i tried doing way , still shows myself. stepped through code make sure, holding different email addresses , is.
protected void wizard1_finishbuttonclick(object sender, wizardnavigationeventargs e) { this.subject = txtsubject.text; this.comment = txtcomment.text; = new mailaddress("myemail@gmail.com"); = 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 code call smtpclient client = new smtpclient();
then in web.config 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 easy way of doing set reply-to header on email before sending follows:
this.replytolist.add(txtemail.text);
Comments
Post a Comment