我一直在使用Rails 3,有关发送真实电子邮件的部分。当我运行该功能向我的Gmail帐户发送电子邮件时,我会收到邮件,但是来自地址也设置为我的Gmail,而不是ticketee@gmail.com
。我有默认设置:来自设置:
class Notifier < ActionMailer::Base
default from: "ticketee@gmail.com"
def comment_updated(comment, user)
@comment = comment
@user = user
mail from: "ticketee@gmail.com", to: user.email, subject: "[ticketee] #{comment.ticket.project.name} - #{comment.ticket.title}"
end
end
关于为什么会发生这种情况的任何想法?
修改
将上述内容从地址更改为我的gmail,我不再将其作为测试响应。但是,它似乎遇到了另一个问题:
Then there should be an email from Ticketee in my box # features/step_definitions/app_email_steps.rb:20
deadlock; recursive locking (ThreadError)
<internal:prelude>:8:in `lock'
<internal:prelude>:8:in `synchronize'
./features/step_definitions/app_email_steps.rb:22:in `block (2 levels) in <top (required)>'
<internal:prelude>:10:in `synchronize'
./features/step_definitions/app_email_steps.rb:21:in `/^there should be an email from Ticketee in my box$/'
features/gmail.feature:32:in `Then there should be an email from Ticketee in my box'
Failing Scenarios:
cucumber features/gmail.feature:20 # Scenario: Receiving a real-world email
答案 0 :(得分:1)
这本书的作者。
default :from
行是错误的。您无法设置电子邮件的发件人地址,因为GMail会强制执行该邮件。您仍然可以为电子邮件设置显示名称,我想:
default from: "From Ticketee, with love <thecorrectemail@gmail.com>"
答案 1 :(得分:1)
我将步骤改为此工作
@mails = @gmail.inbox.find(:unread,from: "didahsutest@gmail.com")
@mails.each do |mail|
if mail.subject =~ /^\[ticketee\]/
@received_mail = true
end
@received_mail.should be_true
end
但我必须删除mail.delete!
因为我收到了这个错误
Label '[Gmail]/Trash' doesn't exist! (Gmail::Message::NoLabelError)