我正在使用Ruby on Rails,您能教我如何使用Mandrill發送和接收郵件。如何使用Mandrill發送和獲取郵件?
我的問題是當用戶輸入文本並按提交,我想要發送郵件到我的郵件。 我已閱讀文檔,但我不明白。
這是我development.rb,同production.rb
ActionMailer::Base.smtp_settings = {
:port => '587',
:address => 'smtp.mandrillapp.com',
:user_name => '[email protected]',
:password => 's82SlRM5dPiKL8vjrJfj4w',
:domain => 'heroku.com',
:authentication => :plain
}
ActionMailer::Base.delivery_method = :smtp
user_mailer.rb:
class UserMailer < ActionMailer::Base
default from: "[email protected]"
def welcome
mail(to: "[email protected]", subject: "Welcome", body: "Have a nice day")
end
end
和控制器:
def index
UserMailer.welcome.deliver
end
我的日誌文件看起來像這個:
Started GET "https://stackoverflow.com/users/" for 127.0.0.1 at 2014-01-21 16:14:10 +0700
Processing by UsersController#index as HTML
Sent mail to [email protected] (2008.0ms)
Date: Tue, 21 Jan 2014 16:14:10 +0700
From: [email protected]
To: [email protected]
Message-ID: <[email protected]>
Subject: Welcome
Mime-Version: 1.0
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
Have a nice day
Rendered text template (0.0ms)
Completed 200 OK in 2018ms (Views: 1.0ms | ActiveRecord: 0.0ms)
謝謝,我試過了,但我還沒有收到任何郵件。 'default from:「[email protected]」 def welcome_email 郵件(至:[email protected],主題:「Welcome to my website」) end' – user3214298
您是否使用過正確的用戶名和apikey?暫時刪除'ENV []',然後插入純字符串。還要確保在你的環境.rb文件中有'config.action_mailer.delivery_method =:smtp'。 –
感謝您的幫助,但它仍然無法正常工作...我發佈了我的文件內容... – user3214298