1

我一直在使用 Rails 3,关于发送真实电子邮件的部分。当我运行该功能向我的 gmail 帐户发送电子邮件时,我收到了邮件,但发件人地址也设置为我的 gmail,而不是ticketee@gmail.com. 我也有默认的 :from setup :

  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,我不再得到 nil 作为测试响应。但是,它似乎遇到了另一个问题:

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
4

2 回答 2

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)
于 2013-03-09T05:20:36.213 回答
1

这本书的作者在这里。

default :from线是错误的。您无法设置电子邮件的发件人地址,因为 GMail 会强制执行。我认为您仍然可以为电子邮件设置显示名称:

default from: "From Ticketee, with love <thecorrectemail@gmail.com>"
于 2012-07-02T04:08:01.480 回答