2012-07-02 67 views
1

我一直在通過Rails 3的行動,發送真正的電子郵件部分。當我運行該功能發送電子郵件到我的gmail帳戶時,我收到郵件,但發件人地址也設置爲我的Gmail,而不是[email protected]。我確實有默認值:從設置以及:rails3inaction發送到gmail

class Notifier < ActionMailer::Base 
    default from: "[email protected]" 

    def comment_updated(comment, user) 
     @comment = comment 
     @user = user 
     mail from: "[email protected]", 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 

回答

1

本書的作者在這裏。

default :from行是一個錯誤。您無法設置電子郵件的發件人地址,因爲GMail會強制執行。您還可以設置一個顯示名稱的電子郵件,我想:

default from: "From Ticketee, with love <[email protected]>" 
+0

謝謝瑞安,我給了一個嘗試,但沒有去。然後我使用我的Gmail地址。但正如我在編輯中所解釋的,我似乎正在接受另一個錯誤。我應該嘗試一種不同的gmail gem版本嗎? – agmcleod

+0

啊,死鎖遞歸錯誤...有時候會發生這種情況。我還沒有調查它爲什麼發生或如何解決它抱歉。 –

1

我改變步這個和它的工作

@mails = @gmail.inbox.find(:unread,from: "[email protected]") 
@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)