sajad torkamani

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, choose Other (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

Leave a comment

Your email address will not be published. Required fields are marked *