简体   繁体   English

从ASP.NET网站发送邮件

[英]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. 我用发送邮件编写了一个网站联系表单,经过数十次研究后找不到答案,希望stackoverflow用户可以提供帮助。

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? aspx.cs文件登录到指定的gmail配置以发送电子邮件。但是,有一种方法可以将SENDER设置为用户在电子邮件文本框中输入的内容,因此不必单击自己的电子邮件,因此在邮箱不回复我自己? 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) 设置mail.From = new MailAddress(地址,显示名称)
  2. in Gmail, go to Mail Settings >> Accounts and Import. 在Gmail中,转到邮件设置>>帐户和导入。
  3. Add the email account you will use as sender in "Send Mail As". 在“发送邮件为”中添加将用作发件人的电子邮件帐户。 (tick as Alias) (打上Alias号)

This is the only way gmail will let you specify the from address. 这是gmail允许您指定发件人地址的唯一方法。

Setting the From Address requires special configuration/confirmation in Gmail for each From Address (see here ), or is otherwise prohibited. 要设置“发件人地址”,需要在Gmail中对每个“发件人地址”进行特殊配置/确认(请参阅此处 ),否则将被禁止。

You could create a generic gmail address such as no-reply-yourapp@gmail.com . 您可以创建一个通用的Gmail地址,例如no-reply-yourapp@gmail.com 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. 然后,使用ReplyToList属性将用户用于回复的默认“回复至”电子邮件地址设置为用户输入的电子邮件地址,以及发件人的适当“显示名称”。

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? 因此,从理论上讲,为了灵活起见,请使用不同的邮件服务(例如提供的Web主机或Outlook等),并将mail.FROM设置为文本框中的值,并将其从用户键入的地址发送出去? Gmail being extra secure causes confusion. Gmail的额外安全性会引起混乱。 Got it. 得到它了。 Thanks guys 多谢你们

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM