How to send an email with a user’s email on the contact page?

I am creating a page with contact details, and I want to receive mail from this page, since its mail was sent from the user's 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 get mail from my mail, not from the user

How to do it?

+3
source share
2 answers

Using gmail, the message will come from the user’s login, not from the "from" user. You can put whatever you want, but it does not work as you expected.

Google Apps, "bot@example.com". gmail , , , .

+5
0

Source: https://habr.com/ru/post/1728156/


All Articles