ruby-on-rails – Configuring smtp Yandex in Rails

Question:

good day

To implement sending messages from the application, we tried two ways: the first is compact, and although not without problems, the message is being sent.

The second one (following the ActionMailer guide ) is not that compact and no messages are sent.

I want to deal with both

Option 1

#app/controllers/feedback_info_controller.rb

def send_mail
 smtp = Net::SMTP.new( "smtp.yandex.ru", 587 )
 smtp.enable_starttls
 smtp.start( "yandex.ru", "my_adr@yandex.ru", "пароль", :plain ) do |conn|
 conn.send_message "Сообщение", "my_adr@yandex.ru", "получатель@rambler.ru"
end

In this case, a letter (without a subject) from MAILER-DAEMON @ comes to the mail recipient@rambler.ru with the following content:

by mail172.rambler.ru (rmaild SMTP 1.2.41)

with ESMTP id 292593804 for получатель@rambler.ru; Mon, 24 Aug 2015 11:13:46 +0300

Received: from forward22m.cmail.yandex.net (forward22m.cmail.yandex.net [5.255.216.16])

    by mx2.mail.rambler.ru (Postfix) with ESMTP id 65FF15CA8
    for <получатель@rambler.ru>; Mon, 24 Aug 2015 11:13:46 +0300 (MSK) 

Received: from smtp3m.mail.yandex.net (smtp3m.mail.yandex.net [IPv6:2a02:6b8:0:2519::125])

    by forward22m.cmail.yandex.net (Yandex) with ESMTP id 488F18046B
    for <получатель@rambler.ru>; Mon, 24 Aug 2015 11:13:46 +0300 (MSK)

Received: from smtp3m.mail.yandex.net (localhost [127.0.0.1])

    by smtp3m.mail.yandex.net (Yandex) with ESMTP id 2C1A127A05B8
    for <получатель@rambler.ru>; Mon, 24 Aug 2015 11:13:46 +0300 (MSK)

Received: by smtp3m.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id lnLUHk87ag-DjpWkB95;

Mon, 24 Aug 2015 11:13:45 +0300

(using TLSv1 with cipher AES128-SHA (128/128 bits))

(Client certificate not present)

Message-Id: <20150824111345.DjpWkB95@smtp3m.mail.yandex.net>

Date: Mon, 24 Aug

2015 11:13:45 +0300

From: MAILER-DAEMON

To: undisclosed-recipients:;

X-Spam: yes

Option 2

Creating and using the FeedbackMailer

   #app/mailers/application_mailer.rb
    class ApplicationMailer < ActionMailer::Base 
    end

   #app/mailers/feedback_mailer.rb
    class FeedbackMailer < ApplicationMailer
    def feedback_email
      mail(from: 'my_adr@yandex.ru', to: 'получатель@rambler.ru', subject: 'тема')
    end
    end 

   #app/controllers/feedback_info_controller.rb
    def feedback_send
       FeedbackMailer.feedback_email
    end

  #config/environments/development.rb
    config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
    config.action_mailer.delivery_method = :smtp
    config.action_mailer.smtp_settings = {
        address: 'smtp.yandex.ru',
        port: 587,
        domain: 'yandex.ru',
        authentication: 'plain',
        user_name: 'my_adr@yandex.ru',
        password: 'пароль',
        enable_starttls_auto: true
    }

nothing happens with these settings

Answer:

config.action_mailer.smtp_settings = {
tls: true,

Without this, yandex does not work. And tls: not in the official documentation.

Scroll to Top