Léo Coletta
Léo Coletta

Reputation: 1269

Rails mailer does not send email

When I try to use rails (5.1.4) mailer, I don't receive any email like I should do. I followed the official rails guide to make it. My config/environment/development.rb :

  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    address:              'smtp.gmail.com',
    port:                 587,
    domain:               'gmail.com',
    user_name:            '[email protected]',
    password:             'app-password-from-google',
    authentication:       'plain',
    enable_starttls_auto: true 
  }

With this config I made a new mailer in mailers/appointement_mailer.rb :

class AppointementMailer < ApplicationMailer
  default :from => "[email protected]"

  def appointement_information(user_email, data)
    @email = user_email
    @body = data
    mail(:to => "[email protected]", :subject => "xxx")
  end
end

This mailer is triggered by a form controlled by a controller, it is located under controllers/contacts_controller.rb :

      def new

      end

      def create
        @appointement = appointement_params
        AppointementMailer.appointement_information(@appointement['email'], @appointement['body'])
        flash[:notice] = "Some message"
        redirect_to articles_path
      end

      private
      def appointement_params
        params.require('appointement').permit(:email, :body)
      end

The form correctly display the flash "Some Message" and no error is written in the console.

Upvotes: 0

Views: 24

Answers (1)

Paul Byrne
Paul Byrne

Reputation: 1615

You need to call deliver_now on your call to the mailer.

AppointementMailer.appointement_information(@appointement['email'], @appointement['body']).deliver_now

Upvotes: 1

Related Questions