How to send an email with user email, in contact us page?

北城以北 提交于 2020-01-02 07:33:12

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/2047916/how-to-send-an-email-with-user-email-in-contact-us-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!