'How to send service emails via Gmail (machine-2-machine) with secure restrictions?
How to send service emails
- from my backend with
smtp.google.comorGmail APIwhile making sure - the secret stored on the backend server can only be used to send emails from a specific sender?
Goal
- send user account activation emails from my backend
- use
smtp.google.comorGmail API(i.e. no own SMTP server) - authenticate with OAuth2.0 (i.e. don't enable "less secure apps")
Current state
- implemented the email sending part
- for testing, I created a
noreply@**.**Google Suite account - for testing, I generated an
accessTokenvia OAuth2 Playground - using the
accessTokenI can send emails viasmtp.googl.com
Problem
- Google suggests to use a
service accountfor this - But to send emails from
[email protected]I have to enable Domain-wide Delegation - Domain-wide delegation allows to impersonate every domain account
- the secret stored on the backend should only allow to send mails from
no-reply@**.**
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
