views:

49

answers:

1

I am creating a contact us page, and i want to receive mails from this page as its a mail came from the user mail.

I wrote this code:

var client = new SmtpClient("smtp.gmail.com", 587)
                {
                    Credentials = new NetworkCredential("[email protected]", "password"),
                    EnableSsl = true
                };
                MailMessage mail = new MailMessage();
                mail.From = new MailAddress("[email protected]");
                mail.To.Add(new MailAddress("[email protected]"));
                mail.Body = "bodyTest";
                mail.Subject = "subjectTest";
                client.Send(mail);

But i receive the mail from my mail not the user

How to do this?

+4  A: 

Using gmail, the message will come from the user logging in, not the user in the "from". You can put whatever you'd like in the from, but it doesn't work the way you'd expect.

Using a small, free Google Apps account, I've actually set up a '[email protected]' account. I log into gmail with that account, so at least contact mail has that as the from.

Jarrett Meyer
The answer above is correct for GMail, if you were using for example Exchange Server you could change the from address to [email protected] but for GMail it takes your credentials login as the from email address.
Nicholas Murray