2014-01-07 54 views
0

我知道這個問題之前已經被問過了,但我仍然無法讓它工作,即使控制檯說它有。從我的ROR4應用程序發送電子郵件

emailer.rb

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



    def welcome_email() 

     @url = 'http://example.com/login' 
     email_with_name = "#{My Name} <#{[email protected]}>" 
     mail(to: email_with_name, subject: 'Test') 
    end 

end 

的environment.rb#(在配置)

config.action_mailer.delivery_method = :smtp 
config.action_mailer.smtp_settings = { 
    address:    'smtp.gmail.com', 
    port:     587, 
    domain:    'example.com', 
    user_name:   '[email protected]', 
    password:    'mypassword', 
    authentication:  'plain', 
    enable_starttls_auto: true } 

爲了測試,我把Emailer.welcome_email().deliver到控制檯

有人告訴我,如果我的設置不正確,可能沒有錯誤出現。

這些設置對所有人都可以嗎?如果是這樣,我可以在哪裏查找問題?

謝謝

+0

你在'log/development.log'中看到了什麼?這篇博文可能對你有所幫助http://nofail.de/2013/10/debugging-rails-applications-in-development/ – phoet

回答

0

我和你有同樣的問題。所有數據似乎都在通過,但沒有發送電子郵件。我實際上在服務器日誌中看到Connection錯誤,這表明我的應用程序無法連接到Google。

我最終找到了這個指令集http://www.leemunroe.com/send-automated-email-ruby-rails-mailgun/並創建了一個免費的MailGun帳戶。這非常簡單。在30分鐘內啓動並運行,而不是使用Google + SMTP失敗的時間。

希望這會有所幫助。祝你好運。

相關問題