So my client has reported that many of the emails are going to the wrong person, and I would like to write some feature tests to find and make sure that they are receiving the email and what it says in my specs. I have mandrill_mailer which uses mandril api, and before it sends out I would like to see what the message is.
所以我的客户报告说很多电子邮件都是错误的人,我想编写一些功能测试来查找并确保他们收到的电子邮件及其在我的规范中说的内容。我有mandrill_mailer使用mandril api,在它发出之前我想知道消息是什么。
For example. Create a new user account -> creates the user, and then sends out a welcome email. in devise it calls RegistrationMailer.new_registration(resource).deliver which then sends a email to the user:
例如。创建一个新用户帐户 - >创建用户,然后发送一封欢迎电子邮件。在设计中,它调用RegistrationMailer.new_registration(resource).deliver,然后发送电子邮件给用户:
def new_registration(user)
user = User.find_by_email(user["email"])
mandrill_mail template: 'new-registration',
subject: 'Welcome to ContentBlvd!',
to: { email: user["email"], name: user["full_name"] },
vars: {
'first_name' => user["full_name"],
'unsubscribe' => "#{CONFIG[:protocol]}#{CONFIG[:host]}/unsubscribe?email=#{user.email}"
}
end
In my mailer how do I test this mail object?
I tried ActionMailer::Base.deliveries, but it returns nil (Since I'm using mandrill mailer...) So I tried - MandrillMailer::TemplateMailer.message But no luck.... Thanks for the help.
在我的邮件程序中,如何测试此邮件对象?我尝试了ActionMailer :: Base.deliveries,但它返回nil(因为我使用的是mandrill邮件程序...)所以我试过 - MandrillMailer :: TemplateMailer.message但是没有运气....感谢您的帮助。
2 个解决方案
#1
1
At this point, MandrillMailer appears to support a robust offline testing set of options. In particular, MandrillMailer.deliveries
can now be examined for expectations or debugging purposes.
此时,MandrillMailer似乎支持强大的离线测试选项集。特别是,现在可以检查MandrillMailer.deliveries的期望或调试目的。
#2
-4
You don't have to use the Mandrill gem to send emails using Mandrill. Just use the Rails default Mailer and add the configuration to application.rb or production.rb to use your Mandrill's account.
您不必使用Mandrill gem来使用Mandrill发送电子邮件。只需使用Rails默认邮件程序并将配置添加到application.rb或production.rb即可使用您的Mandrill帐户。
http://help.mandrill.com/entries/21738467-Using-Mandrill-s-SMTP-integration-with-Web-Frameworks
#1
1
At this point, MandrillMailer appears to support a robust offline testing set of options. In particular, MandrillMailer.deliveries
can now be examined for expectations or debugging purposes.
此时,MandrillMailer似乎支持强大的离线测试选项集。特别是,现在可以检查MandrillMailer.deliveries的期望或调试目的。
#2
-4
You don't have to use the Mandrill gem to send emails using Mandrill. Just use the Rails default Mailer and add the configuration to application.rb or production.rb to use your Mandrill's account.
您不必使用Mandrill gem来使用Mandrill发送电子邮件。只需使用Rails默认邮件程序并将配置添加到application.rb或production.rb即可使用您的Mandrill帐户。
http://help.mandrill.com/entries/21738467-Using-Mandrill-s-SMTP-integration-with-Web-Frameworks