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.