老问题,但首先在 Google...
我最终通过(ab)使用delivery_method = :sendmail 以不同的方式解决了这个问题,这有效地将电子邮件发送到可执行文件;假定为sendmail,但实际上它可以是任何东西。
在您的config/environments/development.rb 中,您可以执行以下操作:
YourApp::Application.configure do
# [...]
config.action_mailer.delivery_method = :sendmail
config.action_mailer.sendmail_settings = {
location: "#{Rails.root}/script/fake-sendmail",
arguments: 'martin+rails@arp242.net',
}
end
然后制作script/fake-sendmail:
#!/bin/sh
sendmail -if fake_sendmail@example.com "$1" < /dev/stdin
(别忘了让这个可执行文件!)
一个相关的解决方案(我更喜欢)是将其附加到 mbox 文件中;这需要很少的设置。
config/environments/development.rb 看起来很相似:
YourApp::Application.configure do
# [...]
config.action_mailer.delivery_method = :sendmail
config.action_mailer.sendmail_settings = {
location: "#{Rails.root}/script/fake-sendmail",
arguments: "'#{Rails.root}/tmp/mail.mbox'",
}
end
script/fake-sendmail 现在看起来像:
#!/bin/sh
echo "From FAKE-SENDMAIL $(date)" >> "$1"
cat /dev/stdin >> "$1"
echo >> "$1"
使用$any电子邮件客户端打开mbox文件...
这是一个非常简单的方法,似乎效果很好。更多细节can be found here(我是这个页面的作者)。