Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Rails 6 - Sending mail from the console (As of April 2021)

1) Create a new gmail account for testing

2) Enable Less secure app access - https://www.google.com/settings/security/lesssecureapps

3) Update config/environments/development.rb

  config.action_mailer.default_url_options = {host: "localhost", port: 3000}
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.perform_deliveries = true
  config.action_mailer.perform_caching = false

  # SMTP settings for gmail
  config.action_mailer.smtp_settings = {
    :address              => "smtp.gmail.com",
    :domain               => "smtp-relay.gmail.com",
    :port                 => 587,
    :user_name            => "[your-gmail-email-address]@gmail.com",
    :password             => "[your-gmail-email-password]",
    :authentication       => "plain",
    :enable_starttls_auto => true,
    :openssl_verify_mode  => "none"
  }

4) Quick rails console test

mail = ActionMailer::Base.mail(from: "your-test-gmail-account-address", to: "another-email-address", subject: "Test", body: "Test")
mail.deliver_now

5) Devise test

User.find_by_email('the-test-email@test.com').deliver_confirmation_instructions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment