· 8 years ago · Oct 17, 2017, 07:36 PM
1#app/controllers/feedback_info_controller.rb
2
3def send_mail
4 smtp = Net::SMTP.new( "smtp.yandex.ru", 587 )
5 smtp.enable_starttls
6 smtp.start( "yandex.ru", "my_adr@yandex.ru", "пароль", :plain ) do |conn|
7 conn.send_message "Сообщение", "my_adr@yandex.ru", "получатель@rambler.ru"
8end
9
10by mx2.mail.rambler.ru (Postfix) with ESMTP id 65FF15CA8
11 for <получатель@rambler.ru>; Mon, 24 Aug 2015 11:13:46 +0300 (MSK)
12
13by forward22m.cmail.yandex.net (Yandex) with ESMTP id 488F18046B
14 for <получатель@rambler.ru>; Mon, 24 Aug 2015 11:13:46 +0300 (MSK)
15
16by smtp3m.mail.yandex.net (Yandex) with ESMTP id 2C1A127A05B8
17 for <получатель@rambler.ru>; Mon, 24 Aug 2015 11:13:46 +0300 (MSK)
18
19#app/mailers/application_mailer.rb
20 class ApplicationMailer < ActionMailer::Base
21 end
22
23 #app/mailers/feedback_mailer.rb
24 class FeedbackMailer < ApplicationMailer
25 def feedback_email
26 mail(from: 'my_adr@yandex.ru', to: 'получатель@rambler.ru', subject: 'тема')
27 end
28 end
29
30 #app/controllers/feedback_info_controller.rb
31 def feedback_send
32 FeedbackMailer.feedback_email
33 end
34
35 #config/environments/development.rb
36 config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
37 config.action_mailer.delivery_method = :smtp
38 config.action_mailer.smtp_settings = {
39 address: 'smtp.yandex.ru',
40 port: 587,
41 domain: 'yandex.ru',
42 authentication: 'plain',
43 user_name: 'my_adr@yandex.ru',
44 password: 'пароль',
45 enable_starttls_auto: true
46 }
47
48config.action_mailer.smtp_settings = {
49tls: true,
50
51#development.rb
52config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
53config.action_mailer.delivery_method = :smtp
54config.action_mailer.smtp_settings = {
55:tls => true,
56address: 'smtp.yandex.ru',
57port: 465,
58domain: 'yandex.ru',
59authentication: 'plain',
60user_name: 'name@yandex.ru',
61password: 'пароль'
62}
63
64
65#mailers/application_mailer.rb
66class ApplicationMailer < ActionMailer::Base
67end
68
69
70#mailers/feedback_mailer.rb
71class FeedbackMailer < ApplicationMailer
72
73def feedback_email (name, phone, comment)
74@name = name
75@phone = phone
76@comment = comment
77mail(from: 'name@yandex.ru', to: 'adrr@example.com', subject: 'Тема пиÑьма')
78end
79end
80
81
82#controllers/feedback_info_controller.rb
83def feedback_send
84
85@name = CGI.escapeHTML(params[:feedback_info][:name])
86@phone = CGI.escapeHTML(params[:feedback_info][:phone])
87@comment = CGI.escapeHTML(params[:feedback_info][:comment])
88
89FeedbackMailer.feedback_email(@name,@phone,@comment).deliver_now
90end
91
92FeedbackMailer.feedback_email.deliver_later
93
94config.action_mailer.default_url_options = { host: 'www.yoursite.ru' }
95config.action_mailer.perform_deliveries = true
96config.action_mailer.delivery_method = :smtp
97config.action_mailer.smtp_settings = {
98 tls: true,
99 address: "smtp.yandex.com",
100 port: 465,
101 domain: "yandex.com",
102 authentication: "plain",
103 enable_starttls_auto: true,
104 user_name: 'youremail@yandex.ru',
105 password: 'yourpassword'
106}