我想从我的ruby应用程序生成电子邮件,所以我使用了Action邮件类。
我在environment.rb上配置了Email设置,我的配置如下
ActionMailer::Base.raise_delivery_errors = false
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "mail.authsmtp.com",
:port => 2525,
:user_name => "*******",
:password => "*******",
:authentication => :login
}
我的邮件程序模型是TestMailer,所以我决定检查邮件操作,因此在TestMailer.rb上定义方法。
def test_mail(to) {
subject "My first email!"
recipients "#{to}"
from 'test'
charset "utf-8"
content_type 'text/html'
body "Testing one two three..."
}
我打开了ruby脚本/控制台,并通过TestMailer.deliver_test_mail("example@gmail.com")
调用了test_mail方法。
它没有生成电子邮件。在应用程序服务器日志中,它会生成电子邮件模板 我不知道这里的问题是什么。
答案 0 :(得分:1)
你应该检查config / environments / development.rb | test.rb | production.rb (取决于你如何启动你的控制台)
并验证它是否不会覆盖environment.rb中的smtp设置
答案 1 :(得分:0)
如果你跑了这个:
ruby script/console
...然后你处于开发模式,可能有“perform_deliveries = false”或 delivery_method 的其他设置
而是在生产模式下运行控制台:
ruby script/console production
...或将config / environments / development.rb更改为“perform_deliveries = true”。
请注意来自environment.rb的这条评论:
# Settings in config/environments/* take precedence over those specified here.
因此,如果在两个地方都定义了某些内容,它将被环境特定设置覆盖!