In config/environments/production.rb (or an initializer):
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.sendgrid.net',
port: 587,
domain: 'yourdomain.com',
user_name: 'apikey', # literal string, not your key
authentication: 'plain',
enable_starttls_auto: true
}
Set the password from the SENDGRID_API_KEY environment variable (for example via Rails credentials or your host's env), not in the settings file. Set the default from to a verified sender: config.action_mailer.default_options = { from: '[YOUR_VERIFIED_SENDER]' }.
Checklist:
1. user_name is exactly 'apikey'. Your account email here fails auth.
2. enable_starttls_auto with port 587. Port 465 needs tls: true instead, which is a different setting.
3. In development, keep delivery_method at :test or use the letter_opener pattern so you do not send real mail.
4. A 403-style failure from the API usually means the key lacks Mail Send scope; an SMTP auth failure usually means the username or pasted key is wrong.