Skip to content

Instantly share code, notes, and snippets.

@dwg
Last active December 27, 2015 18:49
Show Gist options
  • Save dwg/7372744 to your computer and use it in GitHub Desktop.
Save dwg/7372744 to your computer and use it in GitHub Desktop.
Dynamic host mailer example for rails
# Base class
class DynamicHostMailer < ActionMailer::Base
def initialize method_name=nil, host, *args
@host = host
super method_name, *args
end
def url_options
# Host should be checked against a relevant whitelist, this is only an example
{ host: @host }
end
end
# Mailer
class SomeMailer < DynamicHostMailer
def my_mail user
mail to: user.email, from: "[email protected]", subject: "This is an email"
end
end
# Sending
SomeMailer.my_mail request.host_with_port, user
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment