Skip to content

Instantly share code, notes, and snippets.

@kany
Last active August 28, 2023 17:38
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save kany/53f6ce995e788dd94234f69d2a969a95 to your computer and use it in GitHub Desktop.
Rails 6 - Sending mail from the console (As of April 2021)

1) Create a new gmail account for testing

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