MANDRILL MAILER INTEGRATION IN RAILS

Send mail using Mandrill Mailer

We will refer :-

https://github.com/renz45/mandrill_mailer

Add gem in our gemfile

gem 'mandrill_mailer'

If we are using Devise gem then we have to change the devise mailer setting and call our Mailer

config/devise.rb 

      config.mailer = 'InvitationMailer'

Add credentials and mailer setting in our ENV file

config/environments/development.rb

      Rails.application.configure do
       
config.action_mailer.delivery_method = :smtp
          config.action_mailer.perform_deliveries = true
          config.action_mailer.smtp_settings = {
                :address                         =>              "smtp.mandrillapp.com",
                :port                               =>              587,
                :enable_starttls_auto   =>              true,
                :user_name                    =>              'customer-service@.........',
                :password                      =>              'TdX2YR_V9Ifgx4CoLfFVYDCA',
                :authentication             =>              'login',
                :host                               =>              "localhost"
         }
         MandrillMailer.configure do |config|
               config.api_key = 'TdX2YR_V9Ifgsdfgsdgx4CoLfFVYDCA'
         end
        config.action_mailer.default_url_options = { host: "localhost:3000" }
    end

mailer/invitation_mailer.rb

    class InvitationMailer < MandrillMailer::TemplateMailer
       
default from: 'customerservice@........'
          CORPORATE_URL = "http://www.test.test/"

          def site_invitation(invitation, root_url)
              url = "http://#{root_url}/invite/#{invitation.invitation_code}"
              mandrill_mail(
                    template: 'invitation_customers',
                    subject: invitation.subject,
                    to: {email: invitation.email},
                    vars:
                   {
                        'USER_NAME'                   => invitation.name,
                        'USER_EMAIL'                  => invitation.email,
                        'INVITE_URL'                  => url
                  },
                 important: true,
                 inline_css: true
               )
         end
    end

Call  mailer :-

      InvitationMailer.site_invitation(invitation, host).deliver

For DKIM and SPF :-



Popular posts from this blog

CARRIERWAVE - UPLOAD ANY MEDIA (AUDIO , VIDEO AND IMAGE ) FILE IN RAILS

SELECT COUNTRY WITH STATE AND IT'S CITIES RAILS

RAILS: UPLOADING PHOTOS VIA AMAZON S3 AND PAPERCLIP (UPLOADING FILES TO S3 IN RUBY WITH PAPERCLIP)

UNINITIALIZED CONSTANT PAPERCLIP::STORAGE::S3::AWS

CREATE API FOR USER SIGN UP, LOGIN AND CREATE PUBLISHER WITH CURRENT USER

HOW TO CALL RAILS API FROM SIMPLE HTML PAGE.

DEPLOYING PROJECT USING CAPISTRANO (CAPISTRANO IN RAILS)