How to send and receive mail using Mandrill?

I use Ruby on Rails, could you teach me how to use Mandrill to send and receive mail.

My problem is when the user enters text and clicks submit, I want the message to be sent to my mail. I read the documentation, but I do not understand this.

This is my development.rb, the same as 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

and in the controller:

def index
  UserMailer.welcome.deliver
end

My log is as follows:

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)
+4
source share
1 answer

First of all you need to create an account at mandrill.com.

: SMTP API. SMTP .

SMTP API.

development.rb production.rb :

config.action_mailer.smtp_settings = {
  :port =>           '587',
  :address =>        'smtp.mandrillapp.com',
  :user_name =>      ENV['MANDRILL_USERNAME'],
  :password =>       ENV['MANDRILL_APIKEY'],
  :domain =>         'domain.com',
  :authentication => :plain
}

. Mandrill.

, . default_url_options - localhost: 3000, production heroku.com

config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_url_options = { host: "localhost:3000" }

2

, ActionMailer , "UserMailer.welcome.deliver", .

def create
   if @object.save
     UserMailer.welcome.deliver
   else
     render "new"
   end
end
+5

All Articles