good day

To implement the sending of messages from the application, two ways were tested: the first is compact, and at least not without problems, but the message is sent.

The second (following the ActionMailer manual ) is not so 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, the recipient@rambler.ru receives an email (without a topic) from MAILER-DAEMON @ with the following content:

by mail172.rambler.ru (rmaild SMTP 1.2.41)

with ESMTP id 292593804 for recipient@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

Create and use mailer 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

    4 answers 4

     config.action_mailer.smtp_settings = { tls: true, 

    ...

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

      It works with the following settings:

       #development.rb config.action_mailer.default_url_options = { host: 'localhost', port: 3000 } config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { :tls => true, address: 'smtp.yandex.ru', port: 465, domain: 'yandex.ru', authentication: 'plain', user_name: 'name@yandex.ru', password: 'пароль' } #mailers/application_mailer.rb class ApplicationMailer < ActionMailer::Base end #mailers/feedback_mailer.rb class FeedbackMailer < ApplicationMailer def feedback_email (name, phone, comment) @name = name @phone = phone @comment = comment mail(from: 'name@yandex.ru', to: 'adrr@example.com', subject: 'Тема письма') end end #controllers/feedback_info_controller.rb def feedback_send @name = CGI.escapeHTML(params[:feedback_info][:name]) @phone = CGI.escapeHTML(params[:feedback_info][:phone]) @comment = CGI.escapeHTML(params[:feedback_info][:comment]) FeedbackMailer.feedback_email(@name,@phone,@comment).deliver_now end 
      • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

      In the second version, you missed the delivery itself. You have created the letter object, but have not started sending. With Rails 4.2+, you can safely use .deliver_later :

       FeedbackMailer.feedback_email.deliver_later 

      But first re-read the manual , especially this paragraph:

      The behavior of Active Job by default is to run jobs :inline . Therefore, you can use deliver_later to send emails right now, and if you later decide to send emails in a background task, you just need to configure Active Job to use the backend queues (Sidekiq, Resque, etc.).

      • D-side, Thank you! - Kakao Developer

      In Rails 5, for configuration in config/environments/production.rb added:

       config.action_mailer.default_url_options = { host: 'www.yoursite.ru' } config.action_mailer.perform_deliveries = true config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { tls: true, address: "smtp.yandex.com", port: 465, domain: "yandex.com", authentication: "plain", enable_starttls_auto: true, user_name: 'youremail@yandex.ru', password: 'yourpassword' } 

      Everything works fine, including mail for the domain (pdd.yandex.ru). However, unlike gmail, the letter is not saved in the folder sent to the server.