我正在使用Mailgun的Ruby API从标准Rails邮件程序发送电子邮件。但是,由于我没有使用mail
方法,因此预览不起作用:
You are trying to preview an email that does not have any content. This is probably because the mail method has not been called
有没有办法在不使用mail
方法时预览邮件程序?优选地,不需要宝石的那种。
以下是邮寄的样本:
class SuppliersMailer < ApplicationMailer
def send_user_details supplier
@supplier = supplier
message = Mailgun::MessageBuilder.new
message.from default_params[:from]
message.add_recipient :to, "email@example.com", {'first' => "Anna"}
message.subject "My subject"
message.set_html_body template_to_html_string("path/to/template")
message.test_mode(true) if Rails.env.test?
client.send_message ENV["MAILGUN_DOMAIN"], message
end
private
def client
Mailgun::Client.new ENV['MAILGUN_KEY']
end
end
预览课程:
class SuppliersMailerPreview < ActionMailer::Preview
def send_user_details
SuppliersMailer.send_user_details supplier
end
private
def supplier
Supplier.last
end
end