I’m working on a Rails application and need to set up email functionality using ActionMailer. Since I don’t have access to my own SMTP server, I want to use Gmail’s SMTP service to handle the email delivery.
I’m looking for a complete working example that shows:
- The proper ActionMailer configuration settings
- How to set up Gmail account permissions
- Any necessary app configuration files that need to be modified
I’ve tried a few different approaches but keep running into authentication issues. Can someone share a step-by-step setup that actually works? I just need to send basic notification emails from my app to users.
Gmail’s security settings are causing your authentication issues. I had the exact same problem last year with my Rails app. Here’s what fixed it: enable 2FA on your Gmail account, then generate an App Password specifically for your Rails app. Avoid using your regular Gmail password, as Google’s security will block it. In your config/environments/production.rb (or development.rb for testing), set the delivery_method to :smtp with address ‘smtp.gmail.com’, port 587, and enable_starttls_auto to true. It’s best to store your Gmail credentials in Rails credentials or environment variables instead of hardcoding them. Use authentication ‘plain’ rather than ‘login’ for better reliability. Make sure that less secure app access isn’t blocking you, but generating App Passwords should help you bypass that issue.
The App Password approach is right, but here’s what tripped me up during setup. After configuring SMTP, you’ve got to modify your mailer class correctly. Run rails generate mailer NotificationMailer
and set your delivery method explicitly in the environment file. Development and production need separate configs - copying settings between them won’t work. For SMTP config, use your app’s domain, not Gmail’s. Authentication errors usually come from wrong domain settings, not password problems. Make sure your from
address matches the Gmail account you’re using, or Gmail will silently reject emails. Start with a basic welcome email before diving into fancy templates.
just dealt with this same issue. my firewall was blocking port 587 - switched to port 465 with ssl (not starttls) and that fixed the timeouts. also make sure you’re using your full @gmail.com address in the config, not just the username.