Created
December 6, 2024 01:49
-
-
Save trandaison/d860d802921e58e0f384913f2dead77f to your computer and use it in GitHub Desktop.
Rails 7.1 Multiple SMTP Provider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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