Skip to content

Instantly share code, notes, and snippets.

@trandaison
Created December 6, 2024 01:49
Show Gist options
  • Save trandaison/d860d802921e58e0f384913f2dead77f to your computer and use it in GitHub Desktop.
Save trandaison/d860d802921e58e0f384913f2dead77f to your computer and use it in GitHub Desktop.
Rails 7.1 Multiple SMTP Provider
class ApplicationMailer < ActionMailer::Base
default from: '"ZZZ" <[email protected]>'
private
def gmail_delivery
mail.delivery_method.settings = Rails.application.secrets.gmail_smtp
end
def mandrill_delivery
mail.delivery_method.settings = Rails.application.secrets.mandrill_smtp
end
def mailgun_delivery
mail.delivery_method.settings = Rails.application.secrets.mailgun_smtp
end
end
production:
gmail_smtp:
:authentication: "plain"
:address: "smtp.gmail.com"
:port: 587
:domain: "zzz.com"
:user_name: "[email protected]"
:password: "zzz"
:enable_starttls_auto: true
mandrill_smtp:
:authentication: "plain"
:address: "smtp.mandrillapp.com"
:port: 587
:domain: "zzz.com"
:user_name: "[email protected]"
:password: "zzz"
:enable_starttls_auto: true
mailgun_smtp:
:authentication: "plain"
:address: "smtp.mailgun.org"
:port: 587
:domain: "zzz.com"
:user_name: "[email protected]"
:password: "zzz"
:enable_starttls_auto: true
class MyMailer < ApplicationMailer
before_deliver :gmail_delivery, only: :newsletter
before_deliver :mailgun_delivery, only: :reset_password_instruction
def newsletter
# ...
end
def reset_password_instruction
# ...
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment