Identifying senders email id while trying to contact the company through Contact Us form
I am building a Contact Us form for our Company's website.My requirement is that when a user sends any inquiry through our Contact Us page, it should be sent to our company's email id.Lets say firstname.lastname@example.org.I have been provided SMTP details smtp.mycompany.in. I earlier tried sending mail from gmail it was working. Here is my code.
MailMessage mail = new MailMessage(); mail.From = new MailAddress(txtEmail.Text); mail.To.Add("email@example.com"); mail.Subject = "Mail from www.mycompany.in"; mail.Body = emailbody.ToString(); mail.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address smtp.Credentials = new System.Net.NetworkCredential ("firstname.lastname@example.org", "xxxxxx"); //Or your Smtp Email ID and Password // smtp.Port=80; smtp.EnableSsl = true; smtp.Send(mail);
The problem with this code is that when I send mail it is recieved at email@example.com but it always says that the message is from firstname.lastname@example.org instead of the typed email adress txtEmail.Text.I know that is because of the gmail credentials that I provided.So my queston to you guys how can I get it to work such that I know the email id of the sender or the person contacting us.Any suggestions are welcome. Thanks.
You can't do it in this way, as some one is email@example.com other is firstname.lastname@example.org, and you can't send it to appear from the account of someone else.
My suggestion is to add the email address of sender in the body of email that the guy with this email is contacting us but the solution you are trying to do, i think is not possible.
You can't send a message “on behalf of” somebody else if you're using Gmail SMTP. It won't allow you to set custom Reply-To address either.
If you roll out your own SMTP server, you should be good though.
One way to make it less painful both for customers and the support is to set up a ticketing system. You can code one yourself, if you like, or use any of plenty of existing ones.