Skip to content

Instantly share code, notes, and snippets.

@Fivell
Forked from dwg/gist:7372744
Created November 20, 2013 20:46
Show Gist options
  • Save Fivell/7570698 to your computer and use it in GitHub Desktop.
Save Fivell/7570698 to your computer and use it in GitHub Desktop.
# 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