Sending Email Through Cloud Services

Sending email through Azure

Register the application in Azure by referring to this document.

After registration, you can view clientID and tenantID in Overview.

For Client secrets, you can manually add them in Certificates & Secrets.

For sending mails, you need to add Mail.Send permission. For more information, see this document.

The recommended methods for obtaining tokens are auth code flow and client credentials flow

Auth code flow requires the user to log in interactively, and the application can only send emails on behalf of the logged in user.

Client credentials flow does not require the user to log in, but requires the administrator to grant the application permission Mail.Send, which can send messages on behalf of any user. (Most users will want this option as it's a bit simpler.)

Sending email through Google Workspace

To send via API from your Google Workspace account, see this excellent tutorial from Mailtrap. You'll want the "Send email in Laravel using Gmail API" section.

Sending email through Gmail SMTP

This should generally work as expected, using a mail config like below:

MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=mygoogle@gmail.com 
MAIL_PASSWORD=*************
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=mygoogle@gmail.com
MAIL_FROM_NAME="${APP_NAME}"

There are a few limitations to sending email with Gmail:

  • Sending limit – With Gmail SMTP, users have a daily email sending limit, which depends on the Gmail account they use. Exceeding this limit will cause errors or a temporary suspension.
  • Rate limit – Another limit Gmail SMTP users have to deal with is the limit on how many emails they can send per minute or per hour. Exceeding this limit will block or delay your email sending.
  • Security – Sending emails through Gmail SMTP will require a secure connection such as SSL or TLS, which you need to configure correctly in the Gmail SMTP settings. Failing to do so will leave your emails and their data vulnerable to interception and tampering.
    Google’s security settings also require proper configuration of things such as two-factor authentication to avoid the blocking of email sending.
  • Custom domain – For sending emails from a custom domain such as 'yourcompany.com` with Gmail SMTP, you need to configure the correct DNS settings. Not doing so will cause your emails to fail SPF, DKIM, and DMARC authentication checks and thus be marked as spam or simply rejected.