4

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("mymail@gmail.com", "password"),
                    EnableSsl = true
                };
                MailMessage mail = new MailMessage();
                mail.From = new MailAddress("userEmail@any.com");
                mail.To.Add(new MailAddress("mymail@gmail.com"));
                mail.Body = "bodyTest";
                mail.Subject = "subjectTest";
                client.Send(mail);

But i receive the mail from my mail not the user

How to do this?

Amr Elgarhy
  • 66,568
  • 69
  • 184
  • 301

2 Answers2

5

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 'bot@example.com' account. I log into gmail with that account, so at least contact mail has that as the from.

Jarrett Meyer
  • 19,333
  • 6
  • 58
  • 52
  • 2
    The answer above is correct for GMail, if you were using for example Exchange Server you could change the from address to noreply@foobar.com but for GMail it takes your credentials login as the from email address. – Nicholas Murray Jan 12 '10 at 09:59
  • Can you expand more on the workaround? I just implemented a contact-us page and I find it annoying that that I can't receive emails as if it would have been sent from the actual sender. Our mail-server is Google Apps Gmail. – Shimmy Weitzhandler Dec 30 '12 at 08:09
0

I also encountered the same issue, and there is kinda workaround for this, you can add the sender's email to the ReplyToList property, which will give the option to reply to that address.

Shimmy Weitzhandler
  • 101,809
  • 122
  • 424
  • 632