smtp.SendMail not using the from argument

147 views
Skip to first unread message

Dean Schulze

unread,
Sep 9, 2021, 1:19:16 PM9/9/21
to golang-nuts
I'm sending emails with smtp.SendMail() via gmail.  I set the from argument to smtp.SendMail() to a different email address than my gmail username, but the emails still get sent with the From: as my gmail address.

Do I need to do something else to change the From: in the emails, or is gmail always going to use my gmail address?

Thanks.

Roland Müller

unread,
Sep 9, 2021, 4:31:11 PM9/9/21
to Dean Schulze, golang-nuts
Hello,

Am Do., 9. Sept. 2021 um 20:19 Uhr schrieb Dean Schulze <dean.w....@gmail.com>:
I'm sending emails with smtp.SendMail() via gmail.  I set the from argument to smtp.SendMail() to a different email address than my gmail username, but the emails still get sent with the From: as my gmail address.

Do I need to do something else to change the From: in the emails, or is gmail always going to use my gmail address?

I guess gmail uses the address bound to the used account, which would be in my opinion quite reasonable behavior.

BTW this question is a bit OT here since not related to Go rather than mailing policy of Google accounts.

BR,
Roland

Thanks.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/04eb41bd-9002-443b-8921-c3ddcd833c87n%40googlegroups.com.

Dean Schulze

unread,
Sep 9, 2021, 5:03:32 PM9/9/21
to golang-nuts
It could be that I'm not using smtp.SendMail() correctly, which is why I posted it here.  Thanks for your guess, though.

Brian Candler

unread,
Sep 10, 2021, 3:06:02 AM9/10/21
to golang-nuts
If you are using Google's SMTP servers, then it validates the From: header and restricts it to those which you have registered against that account.

You can register additional addresses (including non-Google ones):  Settings > See all settings > Accounts and Import > Send Mail As (Use Gmail to send from your other email addresses) > Add another email address

It will send a verification mail so that you can prove you own that E-mail address.

Dean Schulze

unread,
Sep 11, 2021, 4:47:09 PM9/11/21
to golang-nuts
Thanks for the suggestion.

Unfortunately that doesn't work for Protonmail.  It automatically populates the SMTP Server field with mail.protonmail.ch but it fails to contact that server.  I'll contact ProtonMail support and see if they know how to do this.


Reply all
Reply to author
Forward
0 new messages