0

開発モードで gmail を介して電子メールを送信するように ActionMailer を構成しました。

config/development.rb

config.action_mailer.default_url_options = { host: ENV["MY_DOMAIN"] }
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.smtp_settings = {
  address: "smtp.gmail.com",
  port: 587,
  domain: ENV["MY_DOMAIN"],
  authentication: "plain",
  enable_starttls_auto: true,
  user_name: ENV["MY_USERNAME"],
  password: ENV["MY_PASSWORD"]
}

これをセットアップして、デザイナーがテスト HTML メールをトリガーし、指定されたアドレスに送信して、さまざまなブラウザー/デバイスでテストできるようにします。

ただし、開発モードでは、指定された 1 つのメール アドレスに送信されていないすべての送信メールをブロックしたいと考えています。

私は次のようなものを探しています:

config.action_mailer.perform_deliveries = target_is_designated_email_address?

...しかし、Mail インスタンスを調べて、正しいアドレスに送信されていることを確認する必要があります。

何か案は?

ありがとう!

4

1 に答える 1

2

Check out the Mail interceptors in the mail gem that ActionMailer uses. You can find out more about them in this railscast on ActionMailer.

The relevant part straight from the railscast:

Create a class to redirect mail.

class DevelopmentMailInterceptor
  def self.delivering_email(message)
    message.subject = "[#{message.to}] #{message.subject}"
    message.to = "eifion@asciicasts.com"
  end
end

Register the interceptor in development mode only:

Mail.register_interceptor(DevelopmentMailInterceptor) if Rails.env.development?

Then it will just replace the subject line with "[youremail@blahbalh.com] Some subject" and redirect the message to whomever you want.

于 2012-09-26T16:14:53.433 に答える