discourse/lib/email_builder.rb

28 lines
688 B
Ruby
Raw Normal View History

2013-02-05 14:16:51 -05:00
# Help us build an email
module EmailBuilder
def build_email(to, email_key, params={})
params[:site_name] = SiteSetting.title
params[:base_url] = Discourse.base_url
params[:user_preferences_url] = "#{Discourse.base_url}/user_preferences"
body = I18n.t("#{email_key}.text_body_template", params)
# Are we appending an unsubscribe link?
if params[:add_unsubscribe_link]
body << "\n"
body << I18n.t("unsubscribe_link", params)
end
2013-02-25 11:42:20 -05:00
2013-02-27 18:30:14 -05:00
mail_args = {
to: to,
subject: I18n.t("#{email_key}.subject_template", params),
body: body
}
mail_args[:from] = params[:from] if params[:from].present?
mail(mail_args)
2013-02-05 14:16:51 -05:00
end
2013-02-25 11:42:20 -05:00
end