Ruby on rails 4 尽管有成功通知,但在heroku生产环境中未收到电子邮件
当我在本地主机上运行“rails s”并发送电子邮件时,我会收到一个通知“您的名字已通过电子邮件发送”,并在终端中看到它似乎已经工作。一切都好 但当我将此部署到heroku并发送电子邮件时,我收到一个通知,“您的姓名已通过电子邮件发送”,但从未收到发送到我真正收件箱的电子邮件。你知道我为什么没有收到邮件吗 我已经为用户身份验证系统设置了电子邮件,并在heroku上进行了现场测试,在注册用户时,我通过同一个应用程序收到了发送到我真实收件箱的电子邮件,因此我相信配置设置是正确的 这简直让我发疯!感谢您的帮助:D 终端:Ruby on rails 4 尽管有成功通知,但在heroku生产环境中未收到电子邮件,ruby-on-rails-4,heroku,actionmailer,sendgrid,Ruby On Rails 4,Heroku,Actionmailer,Sendgrid,当我在本地主机上运行“rails s”并发送电子邮件时,我会收到一个通知“您的名字已通过电子邮件发送”,并在终端中看到它似乎已经工作。一切都好 但当我将此部署到heroku并发送电子邮件时,我收到一个通知,“您的姓名已通过电子邮件发送”,但从未收到发送到我真正收件箱的电子邮件。你知道我为什么没有收到邮件吗 我已经为用户身份验证系统设置了电子邮件,并在heroku上进行了现场测试,在注册用户时,我通过同一个应用程序收到了发送到我真实收件箱的电子邮件,因此我相信配置设置是正确的 这简直让我发疯!感谢
Started PUT "/profiles/1/email" for 127.0.0.1 at 2014-10-06 14:45:51 +1100
Processing by ProfilesController#email as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"j7RcI5ec+Uckt5mt6Z0m5iD/KvnoWn/GXNzmHMxOjgg=", "name"=>"Scott", "destination"=>"sdasd@gmail.com", "commit"=>"Send Email", "id"=>"1"}
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 1]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", "1"]]
Profile Load (0.1ms) SELECT "profiles".* FROM "profiles" WHERE "profiles"."user_id" = ? LIMIT 1 [["user_id", 1]]
Rendered user_mailer/profile.html.erb (0.1ms)
Rendered user_mailer/profile.text.erb (0.1ms)
UserMailer#profile: processed outbound mail in 9.3ms
Sent mail to destination (5.5ms)
Date: Mon, 06 Oct 2014 14:45:51 +1100
From: noreply@example.com
To: destination
Message-ID: <5432106f1d6ef_12a33fec3247b7d410068e@S-MacBook-Pro.local.mail>
Subject: Lorem Ipsum bum Lorem Ipsum has shared their name with you
Mime-Version: 1.0
Content-Type: multipart/alternative;
boundary="--==_mimepart_5432106f1c926_12a33fec3247b7d41005c2";
charset=UTF-8
Content-Transfer-Encoding: 7bit
----==_mimepart_5432106f1c926_12a33fec3247b7d41005c2
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
Hi Scott,
Lorem Ipsum bum Lorem Ipsum sent you their name:
First Name: Lorem Ipsum bum
Kind Regards,
Lorem Ipsum bum Lorem Ipsum
----==_mimepart_5432106f1c926_12a33fec3247b7d41005c2
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
<p>Hi Scott,</p>
<p>Lorem Ipsum bum Lorem Ipsum sent you their name:</p>
<li><strong>First Name:</strong>Lorem Ipsum bum</li>
<p>Kind Regards,<br />
Lorem Ipsum bum Lorem Ipsum</p>
----==_mimepart_5432106f1c926_12a33fec3247b7d41005c2--
Redirected to http://localhost:3000/users/1
Completed 302 Found in 21ms (ActiveRecord: 0.3ms)
Started GET "/users/1" for 127.0.0.1 at 2014-10-06 14:45:51 +1100
Processing by UsersController#show as HTML
Parameters: {"id"=>"1"}
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 1]]
Profile Load (0.0ms) SELECT "profiles".* FROM "profiles" WHERE "profiles"."user_id" = ? LIMIT 1 [["user_id", 1]]
Rendered profiles/_profile.html.erb (0.3ms)
Rendered users/show.html.erb within layouts/application (1.3ms)
Rendered layouts/_shim.html.erb (0.1ms)
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
Rendered layouts/_header.html.erb (1.0ms)
Rendered layouts/_footer.html.erb (0.1ms)
Completed 200 OK in 97ms (Views: 95.7ms | ActiveRecord: 0.2ms)
环境/生产:
# Sendgrid config
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
host = 'example.herokuapp.com'
config.action_mailer.default_url_options = { host: host }
ActionMailer::Base.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:authentication => :plain,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => 'heroku.com',
:enable_starttls_auto => true
}
如果这有帮助,下面是一些与用户激活相关的信息-显示其他电子邮件是如何在应用程序中设置的(这些电子邮件在heroku/gmail上测试时在现实生活中有效)
用户控制器:
def email
@user = User.find(params[:id])
destination = params[:to]
name = params[:name]
user = User.find(params[:id])
user_mailer = UserMailer.profile(@profile, destination, name, user)
if user_mailer.deliver
flash[:success] = "Your name was emailed"
redirect_to @user
else
flash[:danger] = "Your name could not be emailed"
redirect_to @user
end
end
def create
@user = User.new(user_params)
if @user.save
@user.profile = Profile.new
@user.send_activation_email
flash[:info] = "Please check your email to activate your account."
redirect_to root_url
else
render 'new'
end
end
模型/用户:
# Sends activation email.
def send_activation_email
UserMailer.account_activation(self).deliver
end
…所以…结果证明我在我的开发环境中没有正确地发送它!:电子邮件说它已经发送了,并且在终端中“发送了”,但是它没有像应该的那样传递目的地变量-因此它没有有效的地方发送电子邮件。(终端将其传递为“目的地”,而不是“目的地”)example@example.com“我没有好好检查一下)。我修正了视图以正确地传递变量,瞧 我重新设置了heroku并手动测试了它-因此我创建了一个新用户,向我的gmail帐户发送了一封激活电子邮件:D。然后我尝试发送第二封电子邮件,它再次通知我该电子邮件已发送,但我的gmail中未出现任何电子邮件:(看起来它可能与config.default\u url选项有关,请删除主机变量并将其设置为config.action\u mailer.default\u url\u options={:host=>'smtp.sendgrid.net'}嘿,我尝试了这一更改并将其推送到heroku-当我从个人资料页面发送电子邮件时,仍然没有收到发送到我gmail的电子邮件。激活用户电子邮件仍然发送(当用户注册时),但此更改断开了该电子邮件中包含的激活链接,该链接将用户发送回网站并激活他们的帐户(好的,那么回到你原来的代码。那么你真的在收件箱中收到了注册电子邮件吗?嘿,是的,已经收到了那部分。注册电子邮件又开始工作了。仍然不知道第二封电子邮件是什么-仍然说已经发过电子邮件,但我的收件箱中没有收到。谢谢主持人的建议!