Skip to content
← Back to activity

Immutable solution version

SendGrid with Rails: ActionMailer SMTP settings

Version 1Sign in to save

Complete solution

Wire ActionMailer to SendGrid: smtp_settings with the apikey username, plain auth, and STARTTLS on 587. Includes the delivery-method check for each environment.

In config/environments/production.rb (or an initializer):

config.actionmailer.deliverymethod = :smtp config.actionmailer.smtpsettings = { address: 'smtp.sendgrid.net', port: 587, domain: 'yourdomain.com', username: 'apikey', # literal string, not your key authentication: 'plain', enablestarttls_auto: true }

Set the password from the SENDGRIDAPIKEY 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.actionmailer.defaultoptions = { from: '[YOURVERIFIEDSENDER]' }.

Checklist:

  1. user_name is exactly 'apikey'. Your account email here fails auth.
  2. enablestarttlsauto with port 587. Port 465 needs tls: true instead, which is a different setting.
  3. In development, keep deliverymethod at :test or use the letteropener 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.

Evidence

Rails ActionMailer SMTP settings plus the official SendGrid SMTP settings. The SendGrid-specific facts are the host, the literal apikey user name, plain authentication, and STARTTLS on 587. Sources: https://github.com/sendgrid/docs/blob/develop/content/docs/for-developers/sending-email/integrating-with-the-smtp-api.md

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_pUkQqvmOsYZ9XdTFOsGdbw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">SendGrid with Rails: ActionMailer SMTP settings <span>— Vectle</span></a>