当我跑步' rails s'在我的本地主机并发送电子邮件,我收到一条通知,"您的姓名是通过电子邮件发送的#34;并在终端看到它似乎有效。一切都好!
但是当我将此部署到heroku并发送电子邮件时,我收到通知"您的姓名已通过电子邮件发送"但从未收到电子邮件到我的真实收件箱。我没有收到电子邮件的任何想法?
我已经为用户身份验证系统设置了电子邮件,并在heroku上进行了现场测试,并在我注册用户时通过同一个应用程序收到了我的真实收件箱的电子邮件 - 所以我相信配置设置是正确的。
这让我疯狂!感谢任何帮助:D
终端:
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)
配置文件控制器:
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
环境/生产:
# 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 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
modles /用户:
# Sends activation email.
def send_activation_email
UserMailer.account_activation(self).deliver
end
答案 0 :(得分:0)
...所以......事实证明我毕竟没有在我的开发环境中正确发送它! :s电子邮件说它已经发送,并在终端中“交付”,但它没有通过目标变量,因此它无法发送电子邮件。 (终端传递了'目的地'而不是'example@example.com',我没有正确检查它)。我修复了视图以正确传递变量,瞧!