我使用这个类行动梅勒轨邮件功能:覆盖在的ActionMailer
class UserMailer < ActionMailer::Base
default from: "[email protected]",
reply_to: '[email protected]'
def mail_method
mail(to: '[email protected]', subject: "SUBJECT")
end
end
所以这样我得到了很多类和发送电子邮件这样从SMTP传输方法的方法。
但是现在我想执行交付,即仅在生产环境中发送电子邮件,而不是在开发或测试环境中。
因此,我只想使用我的电子邮件,这就是为什么我需要重写邮件的方法。
我试过的东西。
- >将函数返回的电子邮件,其中函数名是get_right_email
class UserMailer < ActionMailer::Base
default from: "[email protected]",
reply_to: '[email protected]'
def mail_method
mail(to: get_right_email('[email protected]'), subject: "SUBJECT")
end
end
而且get_right_email的定义如下:
def get_right_email(email)
if(Rails.env=='production')
return email
else
return '[email protected]'
end
end
这将需要一些重构,但仍在可控范围。将需要几个小时,我可以做,但有一个更快的方式,我可以重写邮件功能。
谢谢,它的伟大的发展。我可能会使用它。但是测试环境呢?测试服务器甚至没有浏览器,即使有,也没有人访问它,因为它是一个虚拟机实例。 – user1735921
你想在测试环境中发生什么? – Eoghain
电子邮件应该在测试环境中发送给我 – user1735921