0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Rails + Resendでメール送信

0
Last updated at Posted at 2026-03-17

SMTPでResendをActionMailerに設定する

  1. 前提
    • Resendで API Key を作ってる
    • 送信元に使うドメイン(例:no-reply@your-domain.com)がResend側で使える状態

1. 環境変数を用意する(dotenvでもRenderでもOK)

.env(ローカル用の例)

env
RESEND_API_KEY=re_xxxxxxxxxxxxxxxxx
MAIL_FROM=no-reply@your-domain.com
APP_HOST=localhost:3000
APP_PROTOCOL=http

本番(Render等)は同じキーを環境変数に登録するだけ。

2. ActionMailerのSMTP設定(development / production)

config/environments/development.rb(まずローカルで確認)

.rb
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  address: "smtp.resend.com",
  port: 587,
  user_name: "resend",
  password: ENV.fetch("RESEND_API_KEY"),
  authentication: :login,
  enable_starttls_auto: true
}

config.action_mailer.default_url_options = {
  host: ENV.fetch("APP_HOST"),
  protocol: ENV.fetch("APP_PROTOCOL")
}

config.action_mailer.default_options = {
  from: ENV.fetch("MAIL_FROM")
}

config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true

なぜこの設定になるか
• address/port:ResendのSMTPエンドポイントに繋ぐ(公式が smtp.resend.com)
• user_name:Resendは固定で resend 
• password:SMTPパスワードに APIキーを使う 
• default_url_options:Deviseがメールに入れるURLを作るとき、ここを参照する
• default_options[:from]:送信元。これが未設定/不正だと弾かれる

本番は production.rb に同じ設定を入れて、APP_HOST を本番ドメインにするだけ。

3. Deviseのメールが飛ぶか確認(実際にボタン押す)

Deviseのパスワードリセット画面で送信して、Railsログを見る。

Railsが実際に送ってるかはここが出ればOK:

text
Sent mail to user@example.com (xxxms)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?