質問編集履歴
1
解決
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
開発環境
|
2
|
+
|
3
|
+
|
2
4
|
|
3
5
|
Mac ローカル環境
|
4
6
|
|
@@ -8,212 +10,12 @@
|
|
8
10
|
|
9
11
|
|
10
12
|
|
11
|
-
|
13
|
+
前提・実現したいこと
|
14
|
+
|
15
|
+
|
12
16
|
|
13
17
|
Web上でユーザーからのお問い合わせの際に、ActionMailerを使って「お問い合わせが来ましたよ」というメールを運営側に送りたい
|
14
18
|
|
15
19
|
|
16
20
|
|
17
|
-
###発生している問題・エラーメッセージ
|
18
|
-
|
19
|
-
DBには保存されるが時間切れでメールが送られない。
|
20
|
-
|
21
|
-
|
21
|
+
解決
|
22
|
-
|
23
|
-
Net::ReadTimeout
|
24
|
-
|
25
|
-
```
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
###development.rb
|
30
|
-
|
31
|
-
ここの設定がおかしいのだろうと思う。
|
32
|
-
|
33
|
-
```ruby
|
34
|
-
|
35
|
-
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
|
36
|
-
|
37
|
-
config.mailer = "DeviseMailer"
|
38
|
-
|
39
|
-
ActionMailer::Base.delivery_method = :smtp
|
40
|
-
|
41
|
-
ActionMailer::Base.smtp_settings = {
|
42
|
-
|
43
|
-
enable_starttls_auto: true,
|
44
|
-
|
45
|
-
address: 'svXXX.xserver.jp',
|
46
|
-
|
47
|
-
#port: '587',にしても不可
|
48
|
-
|
49
|
-
port: '465',
|
50
|
-
|
51
|
-
# authentication: 'login'にしても不可,
|
52
|
-
|
53
|
-
authentication: 'plain',
|
54
|
-
|
55
|
-
user_name: 'hoge@example.com',
|
56
|
-
|
57
|
-
password: 'hogehoge',
|
58
|
-
|
59
|
-
domain: 'example.com'
|
60
|
-
|
61
|
-
}
|
62
|
-
|
63
|
-
```
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
###development.rb(Gmailだと問題なく送信される)
|
68
|
-
|
69
|
-
```ruby
|
70
|
-
|
71
|
-
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
|
72
|
-
|
73
|
-
config.mailer = "DeviseMailer"
|
74
|
-
|
75
|
-
ActionMailer::Base.delivery_method = :smtp
|
76
|
-
|
77
|
-
ActionMailer::Base.smtp_settings = {
|
78
|
-
|
79
|
-
enable_starttls_auto: true,
|
80
|
-
|
81
|
-
address: 'smtp.gmail.com',
|
82
|
-
|
83
|
-
port: '587',
|
84
|
-
|
85
|
-
authentication: 'plain',
|
86
|
-
|
87
|
-
user_name: 'hoge@example.com',
|
88
|
-
|
89
|
-
password: 'hogehoge',
|
90
|
-
|
91
|
-
domain: 'example.com'
|
92
|
-
|
93
|
-
}
|
94
|
-
|
95
|
-
```
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
#以下参考コード
|
100
|
-
|
101
|
-
###application_mailer.rb
|
102
|
-
|
103
|
-
```ruby
|
104
|
-
|
105
|
-
class ApplicationMailer < ActionMailer::Base
|
106
|
-
|
107
|
-
layout 'mailer'
|
108
|
-
|
109
|
-
end
|
110
|
-
|
111
|
-
```
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
###contacts_controller.rb
|
116
|
-
|
117
|
-
```ruby
|
118
|
-
|
119
|
-
class ContactsController < ApplicationController
|
120
|
-
|
121
|
-
def new
|
122
|
-
|
123
|
-
@contact = Contact.new
|
124
|
-
|
125
|
-
end
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
def create
|
130
|
-
|
131
|
-
@contact = Contact.create(contact_params)
|
132
|
-
|
133
|
-
redirect_to :root
|
134
|
-
|
135
|
-
ContactMailer.contact(@contact.name, @contact.email, @contact.title, @contact.body).deliver_now
|
136
|
-
|
137
|
-
end
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
private
|
142
|
-
|
143
|
-
def contact_params
|
144
|
-
|
145
|
-
params.require(:contact).permit(:name, :email, :title, :body)
|
146
|
-
|
147
|
-
end
|
148
|
-
|
149
|
-
end
|
150
|
-
|
151
|
-
```
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
###contact_mailer.rb
|
156
|
-
|
157
|
-
```ruby
|
158
|
-
|
159
|
-
class ContactMailer < ApplicationMailer
|
160
|
-
|
161
|
-
default from: "hoge事務局"
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
def contact(name, email, title, body)
|
166
|
-
|
167
|
-
@name = name
|
168
|
-
|
169
|
-
@email = email
|
170
|
-
|
171
|
-
@title = title
|
172
|
-
|
173
|
-
@body= body
|
174
|
-
|
175
|
-
mail(
|
176
|
-
|
177
|
-
to: "hoge@example.com",
|
178
|
-
|
179
|
-
subject: "#{ name }様が、お問い合わせしました。"
|
180
|
-
|
181
|
-
)
|
182
|
-
|
183
|
-
end
|
184
|
-
|
185
|
-
```
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
###contact.text.erb
|
190
|
-
|
191
|
-
```ruby
|
192
|
-
|
193
|
-
<%= @name %>様が、以下の内容でお問い合わせしています。
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
【タイトル】
|
198
|
-
|
199
|
-
<%= @title %>
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
【詳細】
|
204
|
-
|
205
|
-
<%= @body %>
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
早急に確認して、「<%= @email %>」にご連絡ください。
|
210
|
-
|
211
|
-
```
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
###teratail参考質問
|
216
|
-
|
217
|
-
Rails4 Action Mailerでのメール送信にて、ロリポップで作成したメールアカウントで送信エラーになります
|
218
|
-
|
219
|
-
https://teratail.com/questions/47065
|