0

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

CodeDude9
  • 35
  • 3
  • 1
    Could you post some of your code? Are you using the MailMessage class? – parameter Jan 31 '17 at 04:02
  • Yes using system.net.mail and the mailmessage class, tried setting the "from" as the textbox id but still no luck – CodeDude9 Jan 31 '17 at 04:03
  • Is this similar to what you're trying to do? http://stackoverflow.com/questions/3871577/change-sender-address-when-sending-mail-through-gmail-in-c-sharp – Vyrotek Jan 31 '17 at 04:04
  • Vyrotek - yes similar but gmail overwrites like they said is there a none hassle way of just code to handle it rather than configuring gmail? – CodeDude9 Jan 31 '17 at 04:07
  • 1
    They reason they do it is to prevent abuse and spoofing. I'm under the impression you want to be able to send an email from any address enter into a textbox. Even from ones you don't "own". To send an email you need to send it from/to an email server and in my experience all reputable APIs and services require you to prove ownership of the FROM address. – Vyrotek Jan 31 '17 at 04:11
  • Yes, i want to recieve emails FROM what the value of the textbox is entered by the USER on the website – CodeDude9 Jan 31 '17 at 04:12
  • It's always a good idea to include some code to help paint a clearer picture of what you're asking, what you've tried, and what your specific problem is. – Josh Jan 31 '17 at 04:14

3 Answers3

0

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.

parameter
  • 614
  • 10
  • 17
  • Hi Parameter. Okay i understand that for the gmail, what about other mail servers such as webhost provided and outlook etc, do they require the same permission of alias OR is this a GMAIL ONLY thing? – CodeDude9 Jan 31 '17 at 04:11
  • I'd have to imagine you'd have more flexibility with other mail servers, but quick research hasn't led me to any solid answers. Another possibility is setting the ReplyToList property so that your 'reply to' address isn't pointed to yourself. – parameter Jan 31 '17 at 04:22
0

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 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.

David Marchelya
  • 3,352
  • 4
  • 21
  • 24
0

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

CodeDude9
  • 35
  • 3