質問編集履歴
1
内容をより詳細にしました。
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
RailsでActionMailerを用いた時のOpenTimeoutエラーを解決したい
|
test
CHANGED
@@ -6,15 +6,13 @@
|
|
6
6
|
|
7
7
|
【前提】
|
8
8
|
|
9
|
-
|
9
|
+
Ruby on Rails 5を用いてWebアプリケーションを作成しています。
|
10
|
-
|
11
|
-
|
10
|
+
|
12
|
-
|
13
|
-
|
11
|
+
そこで注文が発生した際に、その注文内容がメールで送られてくるようにしたくいです。
|
14
|
-
|
15
|
-
|
12
|
+
|
16
|
-
|
17
|
-
|
13
|
+
それがRailsのActionMailerを用いればできると知り、下記のサイトを参考にコードを書きました。
|
14
|
+
|
15
|
+
|
18
16
|
|
19
17
|
【参考にしたサイト】
|
20
18
|
|
@@ -26,15 +24,11 @@
|
|
26
24
|
|
27
25
|
|
28
26
|
|
29
|
-
おそらく基本的なところからわかっていないです。
|
30
|
-
|
31
|
-
ご教授いただけると幸いです。よろしくお願いいたします。
|
32
|
-
|
33
27
|
|
34
28
|
|
35
29
|
### 発生している問題・エラーメッセージ
|
36
30
|
|
37
|
-
completeアクションが実行される
|
31
|
+
注文確定時にはform_tagでcompleteアクションが実行されるのですが、下記のエラーがでてしまい、メールが送信されません。
|
38
32
|
|
39
33
|
|
40
34
|
|
@@ -42,57 +36,121 @@
|
|
42
36
|
|
43
37
|
**execution expired**
|
44
38
|
|
39
|
+
|
40
|
+
|
41
|
+
なおメーラーをインストールする前は特に問題なく動いていました。
|
42
|
+
|
43
|
+
おそらくcompleteアクション内(下記参照)の
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
**OrderMailer.send_mail(order).deliver_now**
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
部分で何かしらエラーが発生しているものと思われます。
|
52
|
+
|
53
|
+
(binding.pryを用いたところ、その直前までは問題なく動きました)
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
# メーラーに関わる設定など
|
64
|
+
|
65
|
+
###order_mailer.rb
|
66
|
+
|
67
|
+
Order.Mailerモデルにおいてsend_mailメソッドを用いています。
|
68
|
+
|
45
|
-
```
|
69
|
+
```
|
70
|
+
|
46
|
-
|
71
|
+
class OrderMailer < ApplicationMailer
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
def send_mail(order)
|
76
|
+
|
77
|
+
@order = order
|
78
|
+
|
79
|
+
mail(
|
80
|
+
|
81
|
+
from: "from@example.com",
|
82
|
+
|
83
|
+
to: "******@gmail.com",
|
84
|
+
|
85
|
+
subject: "mailerテスト"
|
86
|
+
|
87
|
+
)
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
```
|
94
|
+
|
47
|
-
#order_controller.rb
|
95
|
+
###order_controller.rb
|
96
|
+
|
97
|
+
注文確定時のcompleteアクション
|
98
|
+
|
99
|
+
```
|
100
|
+
|
101
|
+
|
48
102
|
|
49
103
|
def complete
|
50
104
|
|
105
|
+
@order=Order.new(
|
106
|
+
|
107
|
+
name1: session[:name1],
|
108
|
+
|
109
|
+
name2: session[:name2],
|
110
|
+
|
111
|
+
tel1: session[:tel1],
|
112
|
+
|
113
|
+
tel2: session[:tel2],
|
114
|
+
|
115
|
+
tel3: session[:tel3],
|
116
|
+
|
117
|
+
email: session[:email],
|
118
|
+
|
119
|
+
zipcode: session[:zipcode],
|
120
|
+
|
121
|
+
pref: session[:pref],
|
122
|
+
|
123
|
+
addr1: session[:addr1],
|
124
|
+
|
125
|
+
addr2: session[:addr2],
|
126
|
+
|
127
|
+
delivery_date: session[:delivery_date],
|
128
|
+
|
129
|
+
pay_type: session[:pay_type],
|
130
|
+
|
131
|
+
)
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
if order.save
|
136
|
+
|
51
|
-
OrderMailer.send_mail(order).deliver_now
|
137
|
+
OrderMailer.send_mail(order).deliver_now
|
138
|
+
|
52
|
-
|
139
|
+
flash[:notice]="ご注文ありがとうございました"
|
140
|
+
|
141
|
+
render("home/top")
|
142
|
+
|
53
|
-
end
|
143
|
+
end
|
144
|
+
|
54
|
-
|
145
|
+
end
|
146
|
+
|
55
|
-
```
|
147
|
+
```
|
148
|
+
|
56
|
-
|
149
|
+
###config\environment\development.rb
|
57
|
-
|
58
|
-
|
150
|
+
|
59
|
-
|
151
|
+
- 正直このファイルの意味はよくわかっていないです…
|
60
|
-
|
61
|
-
|
62
|
-
|
152
|
+
|
63
|
-
```
|
153
|
+
```
|
64
|
-
|
65
|
-
#order_mailer.rb
|
66
|
-
|
67
|
-
class OrderMailer < ApplicationMailer
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
def send_mail(order)
|
72
|
-
|
73
|
-
@order = order
|
74
|
-
|
75
|
-
mail(
|
76
|
-
|
77
|
-
from: "from@example.com",
|
78
|
-
|
79
|
-
to: "******@gmail.com",
|
80
|
-
|
81
|
-
subject: "mailerテスト"
|
82
|
-
|
83
|
-
)
|
84
|
-
|
85
|
-
end
|
86
|
-
|
87
|
-
end
|
88
|
-
|
89
|
-
```
|
90
|
-
|
91
|
-
```
|
92
|
-
|
93
|
-
#config\environment\development.rb
|
94
|
-
|
95
|
-
|
96
154
|
|
97
155
|
Rails.application.configure do
|
98
156
|
|
@@ -190,9 +248,9 @@
|
|
190
248
|
|
191
249
|
domain: 'gmail.com',
|
192
250
|
|
193
|
-
user_name: '
|
251
|
+
user_name: '******@gmail.com',
|
194
|
-
|
252
|
+
|
195
|
-
password: '
|
253
|
+
password: '******',
|
196
254
|
|
197
255
|
authentication: 'plain',
|
198
256
|
|
@@ -208,10 +266,22 @@
|
|
208
266
|
|
209
267
|
```
|
210
268
|
|
211
|
-
|
269
|
+
###application_mailer.rb
|
270
|
+
|
271
|
+
```
|
272
|
+
|
273
|
+
class ApplicationMailer < ActionMailer::Base
|
274
|
+
|
275
|
+
default from: "from@example.com"
|
276
|
+
|
277
|
+
layout 'mailer'
|
278
|
+
|
279
|
+
end
|
280
|
+
|
281
|
+
```
|
212
282
|
|
213
283
|
### 試したこと
|
214
284
|
|
215
285
|
|
216
286
|
|
217
|
-
mailerのプレビュー機能では問題ありませんでした。
|
287
|
+
mailerのプレビュー機能(localhost:3000/rails/mailers/order_mailer)では問題ありませんでした。
|