小编use*_*298的帖子

如何使用Mandrill发送和获取邮件?

我正在使用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
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

在控制器中:

def index
  UserMailer.welcome.deliver
end
Run Code Online (Sandbox Code Playgroud)

我的日志文件如下所示:

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 …
Run Code Online (Sandbox Code Playgroud)

email ruby-on-rails actionmailer mandrill

4
推荐指数
1
解决办法
3082
查看次数

标签 统计

actionmailer ×1

email ×1

mandrill ×1

ruby-on-rails ×1