我是rails的新手,并使用rails-2.3.5和ruby-1.8.7。这是我的notifier.rb模型:
# app/models/notifier.rb
class Notifier < ActionMailer::Base
default_url_options[:host] = "foo.com"
#This method sends an email with token to users who request a new password
def password_reset_instructions(user)
subject "Password Reset Instructions"
from "Support Team<support@foo.com>"
recipients user.email
sent_on Time.now
body :edit_password_reset_url =>
edit_password_reset_url(user.perishable_token)
end
end
当我调用此方法时,我收到以下错误:
Net::SMTPFatalError in Password resetsController#create
555 5.5.2 Syntax error. 36sm970138yxh.13
我发现一篇文章说这个问题是ruby-1.8.4中的一个错误,修复方法是从:from字段中删除尖括号。果然,如果我只使用“support@foo.com”而不是“支持团队&lt; support@foo.com>”一切正常。
但是,在rails-2.3.5 API或ActionMailer Basics rails指南中没有提及此问题,实际上两者都显示“name&lt; mail address&gt;”在他们的动作管理器设置示例中。谁知道我做错了什么?
答案 0 :(得分:3)
从Travis引用的故障单中,看起来好像可以避免以下问题:
def password_reset_instructions(user)
subject "Password Reset Instructions"
from "Support Team<support@foo.com>"
+ headers "return-path" => 'support@foo.com'
recipients user.email
sent_on Time.now
body :edit_password_reset_url =>
edit_password_reset_url(user.perishable_token)
end
否则,您可以抓住故障单中记录的其中一个补丁或等待2.3.6或3.x
答案 1 :(得分:0)
Rails / ActionMailer打破了这个:
https://rails.lighthouseapp.com/projects/8994/tickets/2340
由于像这样的关键错误没有得到高优先级或临时版本来修复它们在Rails项目中,你要么必须自己修补它,要么等待一段时间来修复它。就像Rails 2.3.4中出现的这个疯狂的错误导致Rails完全无法用于Ruby 1.9:https://rails.lighthouseapp.com/projects/8994/tickets/3144-undefined-method-for-string-ror-234。花了好几个月来解决这个问题。
答案 2 :(得分:0)
问题是来自rails 2.3.4和2.3.5中使用的ActionMailer :: Base的perform_delivery_smtp方法。你总是可以尝试猴子补丁 - 就像那样:
class ApplicationMailer < ActionMailer::Base
def welcome_email(user)
recipients user.email from "Site Notifications<notifications@example.com>"
subject "Welcome!"
sent_on Time.now
...
end
def perform_delivery_smtp(mail)
destinations = mail.destinations
mail.ready_to_send
sender = mail['return-path'] || mail.from
smtp = Net::SMTP.new(smtp_settings[:address], smtp_settings[:port])
smtp.enable_starttls_auto if smtp_settings[:enable_starttls_auto] && smtp.respond_to?(:enable_starttls_auto)
smtp.start(smtp_settings[:domain], smtp_settings[:user_name], smtp_settings[:password],
smtp_settings[:authentication]) do |smtp|
smtp.sendmail(mail.encoded, sender, destinations)
end
end
end