我试图在我的网站上插入邮件功能, 但它一直出错,我找不到任何答案买谷歌搜索
我不是专家,所以即使这是一个初级问题,请理解,如果需要任何信息,请告诉我!
这是我的代码。
index.html.erb
<a href="/home/email_test">test</a>
home_controller.rb
def email_test
@user = User.last
UserMailer.welcome_email(@user).deliver_now
redirect_to :back
end
环境/ development.rb (我尝试引用和取消引用端口号587,并更改autentication:plain和:login)
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'gmail.com',
user_name: 'my_mail_id@gmail.com',
password: 'my_mail_password',
authentication: :plain,
enable_starttls_auto: true
}
寄件人/ user_mailer.rb
class UserMailer < ApplicationMailer
default from: "my_mail_id@gmail.com"
def welcome_email(user)
@user = user
mail(to: @user.email, subject: 'Welcome to My Awesome Site')
end
end
这是我在控制台中的错误代码
Started GET "/home/email_test" for 121.140.234.142 at 2017-04-06 04:17:09 +0000
Cannot render console from 121.140.234.142! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by HomeController#email_test as HTML
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."inactive" = 'f' AND "users"."id" = ? ORDER BY "users"."id" ASC LIMIT 1 [["id", 1]]
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."inactive" = 'f' ORDER BY "users"."id" DESC LIMIT 1
Rendered user_mailer/welcome_email.html.erb within layouts/mailer (0.1ms)
Rendered user_mailer/welcome_email.text.erb within layouts/mailer (0.1ms)
UserMailer#welcome_email: processed outbound mail in 11.2ms
Sent mail to user_mail_id@user_mail.com (1123.5ms)
Date: Thu, 06 Apr 2017 04:17:09 +0000
From: my_mail_id@gmail.com
To: user_mail_id@user_mail.com
Message-ID: <58e5c145eb445_8eb3fc731278548409bb@~~.mail>
Subject: Welcome to My Awesome Site
Mime-Version: 1.0
Content-Type: multipart/alternative;
boundary="--==_mimepart_58e5c145ea640_8eb3fc73127854840896";
charset=UTF-8
Content-Transfer-Encoding: 7bit
----==_mimepart_58e5c145ea640_8eb3fc73127854840896
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: base64
CuyasOyDgeyaseuLmCwgZXhhbXBsZS5jb23sl5Ag7Ja07ISc7Jik7IS47JqU
Lgo9PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PQogCmV4YW1wbGUuY29t7JeQIOqwgOyehe2VmOyFqOyKteuLiOuLpC4g
64u57Iug7J2YIHVzZXJuYW1l7J2AIOyasOyDgeyaseyeheuLiOuLpC4KIArs
nbQg7IKs7J207Yq47JeQIOuhnOq3uOyduO2VmOq4sCDsnITtlbTshJzripQg
aHR0cDovL2xhbmdkeS5uZXQvdXNlcnMvc2lnbl9pbuydhCDtgbTrpq3tlbTs
o7zshLjsmpQuCiAK6rCA7J6F7ZW07KO87IWU7IScIOqwkOyCrO2VqeuLiOuL
pC4K
----==_mimepart_58e5c145ea640_8eb3fc73127854840896
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: base64
PGh0bWw+CiAgPGJvZHk+CiAgICA8IURPQ1RZUEUgaHRtbD4KPGh0bWw+CiAg
PGhlYWQ+CiAgICA8bWV0YSBjb250ZW50PSd0ZXh0L2h0bWw7IGNoYXJzZXQ9
VVRGLTgnIGh0dHAtZXF1aXY9J0NvbnRlbnQtVHlwZScgLz4KICA8L2hlYWQ+
CiAgPGJvZHk+CiAgICA8aDE+7Jqw7IOB7Jqx64uYLCBleGFtcGxlLmNvbeyX
kCDslrTshJzsmKTshLjsmpQuPC9oMT4KICAgICAgPHA+CiAgICAgIGV4YW1w
bGUuY29t7JeQIOqwgOyehe2VmOyFqOyKteuLiOuLpC4KICAgICAg64u57Iug
7J2YIHVzZXJuYW1l7J2AIOyasOyDgeyaseyeheuLiOuLpC48YnI+CiAgICA8
L3A+CiAgICA8cD4KICAgICAg7J20IOyCrOydtO2KuOyXkCDroZzqt7jsnbjt
lZjquLAg7JyE7ZW07ISc64qUIGh0dHA6Ly9sYW5nZHkubmV0L3VzZXJzL3Np
Z25faW7snYQg7YG066at7ZW07KO87IS47JqULgogICAgPC9wPgogICAgPHA+
6rCA7J6F7ZW07KO87IWU7IScIOqwkOyCrO2VqeuLiOuLpC48L3A+CiAgPC9i
b2R5Pgo8L2h0bWw+CiAgPC9ib2R5Pgo8L2h0bWw+Cg==
----==_mimepart_58e5c145ea640_8eb3fc73127854840896--
Completed 500 Internal Server Error in 1150ms (ActiveRecord: 0.5ms)
RestClient::BadRequest (400 Bad Request):
app/controllers/home_controller.rb:137:in `email_test'
Rendered /usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/_source.erb (5.7ms)
Rendered /usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (2.7ms)
Rendered /usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.6ms)
Rendered /usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (30.0ms)
请让我知道任何想法!