Tan Nguyen
Tan Nguyen

Reputation: 65

Can not send email by Mailer Rails

I have tried to configure like the tutorials but still can not send email. At the console, it displays the image below:

enter image description here

I have configured in config file \ environments \ development.rb and production.rb as follows:

config.active_record.dump_schema_after_migration = false
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    address:              'smtp.gmail.com',
    port:                 587,
    domain:               'gmail.com',
    user_name:            'gmail username',
    password:             'password',
    authentication:       'plain',
    enable_starttls_auto: true  }

app\mailers\user_mailer.rb:

class UserMailer < ApplicationMailer

  def registration_confirmation(user)
    mail(:to => user.email,:subject => "registered")
  end
end

app\mailers\application_mailer.rb

class ApplicationMailer < ActionMailer::Base
  default from: "[email protected]"
  layout 'mailer'
end

app\controllers\users_controller.rb

def create
    @user = User.new(user_params)
    UserMailer.registration_confirmation(@user).deliver
    respond_to do |format|
      if @user.save

        format.html { redirect_to @user, notice: 'User was successfully created.' }
        format.json { render :show, status: :created, location: @user }
      else
        format.html { render :new }
        format.json { render json: @user.errors, status: :unprocessable_entity }
      end
    end
  end

It runs without any mistakes have been displayed but when I checked gmail, it's not receive any mail.

Upvotes: 0

Views: 96

Answers (1)

Umar Khan
Umar Khan

Reputation: 1430

Are you providing the correct email and password in your development.rb file?

One more thing: You are sending email from this id "[email protected]", please login with this email in gmail. Just to make sure that everything is ok with your account. May be some kind of issue in authentication with your account.

Upvotes: 1

Related Questions