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 sales@mycompany.in.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("sales@mycompany.in");
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
("mycompany@gmail.com", "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 sales@mycompany.in but it always says that the message is from mycompany@gmail.com 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.

Answers


You can't do it in this way, as some one is abc@yahoo.com other is xyz@hotmail.com, 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.


In Theory

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.

In Practice

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.


Need Your Help

GCC optimize return value

c++ gcc return-value pass-by-reference

This question is related to Function returning value vs modifying value passed by reference. I want to know if gcc will optimize the following the same way. Imagine the two functions do the same th...

Unknown error the true part of if state dosen't work

javascript html

I've write a code for simple pass and username form that will show up a content if u entered the user and password correct