Sender action does not send / receive electronic rails 5

I am trying to create a simple blog (using rails 5) and want to send updates by email to users when I post something new. I am trying to use actionmailer and I am using a program to register users. At first I try to configure it only from the first user.

When I look at my local server, an email message appears, but it is not received. Any advice would be greatly appreciated. I am stuck.

    UserNotifierMailer#sample_email: processed outbound mail in 410.4ms
Sent mail to myemail@gmail.com (853.2ms)
Date: Wed, 27 Jul 2016 12:05:33 +0100
From: from@example.com
To:myemail@gmail.com
Message-ID: <5798957d9de31_ae813ff962abfe1466438@Unknown-7c-d1-c3-78-04-d2.home.mail>
Subject: Sample Email
Mime-Version: 1.0
Content-Type: multipart/alternative;
 boundary="--==_mimepart_5798957d951e2_ae813ff962abfe1466312";
 charset=UTF-8
Content-Transfer-Encoding: 7bit

My message controller is as follows:

def create
    @user = User.first
    @post = current_user.posts.build(post_params)
    if @post.save
      flash[:success] = "Your post has been created!"
      UserNotifierMailer.sample_email(@user).deliver
      redirect_to posts_path
    else
      flash[:alert] = "Your new post couldn't be created!  Please check the form."
      render :new
    end
  end

My mail is as follows:

class UserNotifierMailer < ApplicationMailer
  default from: "from@example.com"
  def sample_email(user)
    @user = user
    @url = 'http://www.google.com'
    mail(to: @user.email, subject: 'Sample Email')
  end
end

and in my development.rb I have the following settings:

config.action_mailer.raise_delivery_errors = true
  config.action_mailer.perform_deliveries = true
  config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }

  config.action_mailer.delivery_method = :smtp

  config.action_mailer.smtp_settings = {
    address: "smtp.gmail.com",
    port: 587,
    domain: "gmail.com",
    authentication: "plain",
    enable_starttls_auto: true,
    user_name: "my_gmail_username",
    password: "my_gmail_password"
  }
+4
2

Gmail:

  • Account Settings Than

  • Sign-in & security, Connected apps & sites

  • , Allow less secure apps... .

+2
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
...
config.action_mailer.delivery_method = :smtp

, .

config.action_mailer.default_url_options = { host: 'localhost:3000' }

.deliver_later .deliver_now, .deliver

0

Source: https://habr.com/ru/post/1649276/


All Articles