我有一个客户邮件设置与设计,如下所示:
class DeviseMailer < Devise::Mailer
default from: "hello@example.com"
def mandrill_client
@mandrill_client ||= Mandrill::API.new MANDRILL_API_KEY
end
def confirmation_instructions(record, token, opts={})
template_name = "user-confirm-account"
template_content = []
message = {
to: [{email: record.email}],
subject: "Confirm Your account",
merge_vars: [
{rcpt: record.email,
vars: [
{name: "CONFIRM_ACCOUNT_LINK", content: "#{root_url}users/confirmation?confirmation_token=#{token}"},
]
}
]
}
mandrill_client.messages.send_template template_name, template_content, message
end
def reset_password_instructions(record, token, opts={})
template_name = "user-forgot-password"
template_content = []
message = {
to: [{email: record.email}],
subject: "Password Reset",
merge_vars: [
{rcpt: record.email,
vars: [
{name: "PASSWORD_RESET_LINK", content: "#{root_url}users/password/edit?reset_password_token=#{token}"},
]
}
]
}
mandrill_client.messages.send_template template_name, template_content, message
end
def unlock_instructions(record, token, opts={})
# code to be added here later
end
end
这很有效。我这样做是为了我可以自定义Mandrill发送的确认电子邮件。要发送确认电子邮件,请致电以下人员:
@user.send_confirmation_instructions
这有效但我希望能够根据我传递给邮件程序的参数为confirmation_instructions发送不同的模板。例如source=contactform
。如何在我的@user.send_confirmation_instructions
代码中包含参数,然后在邮件程序中检索它?谢谢! :)