質問編集履歴
1
コードの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -2,4 +2,53 @@
|
|
2
2
|
|
3
3
|
ネットで調べてgmailから送る方法が書かれているページがあったので、やってみたのですが、エラーは出ないのにメールが送信されません。何が原因なのでしょうか?
|
4
4
|
|
5
|
-
アクション内で、メールを送るコードのあとにリダイレクトを記述をしているのですが、リダイレクトはうまくいくのに、メールは送られません。
|
5
|
+
アクション内で、メールを送るコードのあとにリダイレクトを記述をしているのですが、リダイレクトはうまくいくのに、メールは送られません。
|
6
|
+
|
7
|
+
config/environments/production.rbのファイルに以下の記述をしています。
|
8
|
+
|
9
|
+
require "mail"
|
10
|
+
config.action_mailer.raise_delivery_errors = true
|
11
|
+
config.action_mailer.delivery_method = :smtp
|
12
|
+
config.action_mailer.smtp_settings = {
|
13
|
+
port: 587,
|
14
|
+
address: 'smtp.gmail.com',
|
15
|
+
domain: 'gmail.com',
|
16
|
+
user_name: 'メールアドレス',
|
17
|
+
password: 'パスワード',
|
18
|
+
authentication: 'login',
|
19
|
+
enable_starttls_auto: true
|
20
|
+
}
|
21
|
+
|
22
|
+
mailerには以下の記述をしています。
|
23
|
+
|
24
|
+
class ○○Mailer < ApplicationMailer
|
25
|
+
default from: 'gmailのメールアドレス'
|
26
|
+
|
27
|
+
def demo
|
28
|
+
mail :to => "送信先アドレス",
|
29
|
+
:subject => 'テスト'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
コントローラーで以下の記述をしています。
|
34
|
+
|
35
|
+
def send_email
|
36
|
+
○○Mailer.demo.deliver
|
37
|
+
|
38
|
+
redirect_to("/top")
|
39
|
+
end
|
40
|
+
|
41
|
+
views/○○_mailer/demo.html.erb には以下の記述をしています。
|
42
|
+
|
43
|
+
<!DOCTYPE html>
|
44
|
+
<html>
|
45
|
+
<head>
|
46
|
+
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
|
47
|
+
</head>
|
48
|
+
<body>
|
49
|
+
<p>ご登録ありがとうございます。</p>
|
50
|
+
</body>
|
51
|
+
</html>
|
52
|
+
|
53
|
+
|
54
|
+
ご回答お願いいたします。
|