我正在使用Ruby on Rails,你能教我如何使用Mandrill发送和接收邮件吗。
我的问题是当用户输入文本并提交时,我希望消息发送到我的邮箱。 我已经阅读了文档,但我不理解它。
这是我的development.rb文件,与production.rb相同。
ActionMailer::Base.smtp_settings = {
:port => '587',
:address => 'smtp.mandrillapp.com',
:user_name => 'myemail@gmail.com',
:password => 's82SlRM5dPiKL8vjrJfj4w',
:domain => 'heroku.com',
:authentication => :plain
}
ActionMailer::Base.delivery_method = :smtp
user_mailer.rb:
class UserMailer < ActionMailer::Base
default from: "from@example.com"
def welcome
mail(to: "morumotto26@gmail.com", subject: "Welcome", body: "Have a nice day")
end
end
在控制器中:
def index
UserMailer.welcome.deliver
end
我的日志文件看起来像这样:
Started GET "/users/" for 127.0.0.1 at 2014-01-21 16:14:10 +0700
Processing by UsersController#index as HTML
Sent mail to morumotto26@gmail.com (2008.0ms)
Date: Tue, 21 Jan 2014 16:14:10 +0700
From: myemail@gmail.com
To: morumotto26@gmail.com
Message-ID: <52de3a62c89b2_5e8c9ea1881631@tnkjapan10.mail>
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)
默认发件人:"myemail@gmail.com" def welcome_email mail(to: blahblah@gmail.com, subject: "欢迎来到我的网站") end
- user3214298ENV[]
并插入纯字符串。另外,请确保在你的环境 .rb 文件中有config.action_mailer.delivery_method =:smtp
。 - Ilya CherevkovActionMailer::Base
重命名为config.action_mailer
,就像我的答案中所示。此外,您可以尝试直接将ActionMailer::Base.smtp_settings = {}
和ActionMailer::Base.delivery_method
移动到您的user_mailer.rb
中。 - Ilya Cherevkov