Configure Action Mailer with Gmail SMTP
11 March 2022 (Updated 25 April 2022)
Create an app password with your Google account
- Go to your Google Account page.
- Select Security from the left side menu
- Select Signing in to Google > App passwords
- Under
Select the app and device you want to generate the app password for
, chooseOther (Custom name)
and enter a name. - Click on
Generate
to generate a password. - Save the password somewhere safe (e.g., LastPass vault).
Configure credentials
Add the following to config/environments/development.rb
:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'example.com',
username: Rails.application.credentials.smtp!.development!.username!,
password: Rails.application.credentials.smtp!.development!.password!,
authentication: 'plain',
enable_starttls_auto: true,
open_timeout: 5,
read_timeout: 5
}
You’ll want to store the SMTP password in config/credentials.yml.enc
. See this post for more info.
See the docs for configuration options.
Tagged:
Rails
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment