幾周前,我創建了一個郵件程序對象,在創建新「Thing」時發送電子郵件。它工作順利,但我後來評論了相關的路線,並沒有處理它一段時間。今天我又試了一次,什麼都沒有發生。我發現我使用的電子郵件帳戶由於某種原因已被斷開連接,所以我用另一個電子郵件帳戶嘗試過。依然沒有。有沒有人猜測爲什麼它可能沒有做任何事情,或者我可以如何調試它?我確定用戶名/密碼/域名是準確的。Mailer在切換電子郵件後停止工作
配置/環境/ development.rb
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'gmail.com',
user_name: 'username',
password: 'password',
authentication: 'plain',
enable_starttls_auto: true
}
應用程序/郵寄者/ user_mailer.rb
class UserMailer < ActionMailer::Base
default from: '[email protected]'
def notify(user)
@user = user
mail(to: @user.email,subject: "Notification")
end
end
應用/視圖/ user_mailer文件/ notify.html.erb
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
<h1>Heading</h1>
<p>First paragraph</p>
<p>Second paragraph</p>
</body>
</html>
應用程序/控制器/ users_controller.rb
def create
#...
UserMailer.notify(@user).deliver
end
待辦事項你有一個測試/規範來驗證電子郵件是否被髮送,並且內容/屬性如預期的那樣?這是驗證郵件程序功能正在工作的更好方法;比嘗試手動觸發電子郵件更好。這可能是電子郵件仍在發送,但本地的一些smtp問題正在壓制它。另外,郵件程序的功能是否適用於生產? –
也許你必須在電子郵件配置中啓用對你的應用程序的訪問,爲什麼你不試試? http://stackoverflow.com/a/26374624/3851249 –
爲交付添加爆炸符號,並讓我們知道,錯誤是什麼?和郵件不會去垃圾箱右.. ..? – Nithin