当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Sending mail from website in ASP.NET

问题描述:

I coded a website contact form with mail send and after dozens of research cannot find an answer hoping stackoverflow users can help.

The aspx.cs file signs into the specified gmail configuration to send the email HOWEVER is there a way to set the SENDER as what the user inputs in the email textbox, so instead of recieving the email from myself so when clicking "Reply" on the mailbox its not replying to myself? If that makes sense?

So the sender is not me but the sender is what the user inputs in the mail box and I receive the email FROM the input value rather than myself

网友答案:

From comments:

This is the solution:

  1. set mail.From = new MailAddress(address, display name)
  2. in Gmail, go to Mail Settings >> Accounts and Import.
  3. Add the email account you will use as sender in "Send Mail As". (tick as Alias)

This is the only way gmail will let you specify the from address.

网友答案:

Setting the From Address requires special configuration/confirmation in Gmail for each From Address (see here), or is otherwise prohibited.

You could create a generic gmail address such as [email protected]. Then use the ReplyToList property to set the default Reply To email address that the user will use for their reply, to the user input email address, as well as an appropriate Display Name for the sender.

网友答案:

So in theory, for flexibilty use different mail service such as web host provided or outlook etc and set the mail.FROM to the value from the textbox and it will be sent from the address the user has typed? Gmail being extra secure causes confusion. Got it. Thanks guys

分享给朋友:
您可能感兴趣的文章:
随机阅读: