我检索了在Ruby on Rails下开发的API。我把它安装在我的服务器上,一切都运行得很好,除了电子邮件。
我无法从服务器发送电子邮件,也无法在日志中找到错误消息或终端中的任何相关信息。
config/environments/development.rb
中的配置如下所示:
# ActionMailer Config
config.action_mailer.default_url_options = { :host => 'domain.com' }
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
config.action_mailer.asset_host = 'http://app.domain.com'
ActionMailer::Base.smtp_settings = {
:address => '127.0.0.1',
:port => '1025',
:authentication => :plain,
:user_name => Rails.application.secrets.sendgrid_username,
:password => Rails.application.secrets.sendgrid_password,
:domain => 'domain.com',
:enable_starttls_auto => true
}
密码重置电子邮件的发送方式与authentication_controller中的相同:
# send email
UserMailer.password_reset_email(@user, rand).deliver
head :no_content
UserMailer类看起来像这样:
class UserMailer < ApplicationMailer
def password_reset_email(user, pw_reset_code)
@user = user
@pw_reset_code = pw_reset_code
mail(to: @user.email, subject: 'Password reset on Domain app')
end
end
如何修复电子邮件或至少调试此情况?
更新18.09.2017
以下是我尝试申请新密码时记录的信息:
Started POST "/generate_pw_reset.json" for 127.0.0.1 at 2017-09-18 12:17:21 +0200
Processing by AuthenticationController#generate_pw_reset as JSON
Parameters: {"email"=>"email@gmail.com", "api_key"=>"vvfregregregrege", "authentication"=>{"email"=>"email@gmail.com", "api_key"=>"vvfregregregrege"}}
Can't verify CSRF token authenticity
[1m[35mUser Load (0.9ms)[0m SELECT "users".* FROM "users" WHERE "users"."email" = 'email@gmail.com' LIMIT 1
[1m[36m (0.3ms)[0m [1mBEGIN[0m
[1m[35mUser Exists (0.6ms)[0m SELECT 1 AS one FROM "users" WHERE ("users"."email" = 'email@gmail.com' AND "users"."id" != 1) LIMIT 1
[1m[36mSQL (0.4ms)[0m [1mUPDATE "users" SET "password_reset_code" = $1, "updated_at" = $2 WHERE "users"."id" = 1[0m [["password_reset_code", 9197196061], ["updated_at", "2017-09-18 10:17:21.263062"]]
[1m[35m (29.7ms)[0m COMMIT
Rendered user_mailer/password_reset_email.html.erb within layouts/mailer (0.2ms)
UserMailer#password_reset_email: processed outbound mail in 16.3ms
Sent mail to email@gmail.com (6.2ms)
Date: Mon, 18 Sep 2017 12:17:21 +0200
From: contact@nightspree.com
To: email@gmail.com
Message-ID: <59bf9d314cad2_1ab939f22b96051c153e4@ns3045608.ip-149-202-219.eu.mail>
Subject: Password reset on Nightspree app
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!-- If you delete this meta tag, Half Life 3 will never be released. -->
<meta name="viewport" content="width=device-width" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Nightspree</title>
<style type="text/css">
/* -------------------------------------
GLOBAL
------------------------------------- */
* {
margin:0;
padding:0;
}
* { font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif; }
img {
max-width: 100%;
}
.collapse {
margin:0;
padding:0;
}
body {
-webkit-font-smoothing:antialiased;
-webkit-text-size-adjust:none;
width: 100%!important;
height: 100%;
}
/* -------------------------------------
ELEMENTS
------------------------------------- */
a { color: #2BA6CB;}
.btn {
text-decoration:none;
color: #FFF;
background-color: #666;
padding:10px 16px;
font-weight:bold;
margin-right:10px;
text-align:center;
cursor:pointer;
display: inline-block;
}
p.callout {
padding:15px;
background-color:#ECF8FF;
margin-bottom: 15px;
}
.callout a {
font-weight:bold;
color: #2BA6CB;
}
table.social {
/* padding:15px; */
background-color: #ebebeb;
}
.social .soc-btn {
padding: 3px 7px;
font-size:12px;
margin-bottom:10px;
text-decoration:none;
color: #FFF;font-weight:bold;
display:block;
text-align:center;
}
a.fb { background-color: #3B5998!important; }
a.tw { background-color: #1daced!important; }
a.gp { background-color: #DB4A39!important; }
a.ms { background-color: #000!important; }
.sidebar .soc-btn {
display:block;
width:100%;
}
/* -------------------------------------
HEADER
------------------------------------- */
table.head-wrap { width: 100%;}
.header.container table td.logo { padding: 15px; }
.header.container table td.label { padding: 15px; padding-left:0px;}
/* -------------------------------------
BODY
------------------------------------- */
table.body-wrap { width: 100%;}
/* -------------------------------------
FOOTER
------------------------------------- */
table.footer-wrap { width: 100%; clear:both!important;
}
.footer-wrap .container td.content p { border-top: 1px solid rgb(215,215,215); padding-top:15px;}
.footer-wrap .container td.content p {
font-size:10px;
font-weight: bold;
}
/* -------------------------------------
TYPOGRAPHY
------------------------------------- */
h1,h2,h3,h4,h5,h6 {
font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif; line-height: 1.1; margin-bottom:15px; color:#000;
}
h1 small, h2 small, h3 small, h4 small, h5 small, h6 small { font-size: 60%; color: #6f6f6f; line-height: 0; text-transform: none; }
h1 { font-weight:200; font-size: 44px;}
h2 { font-weight:200; font-size: 37px;}
h3 { font-weight:500; font-size: 27px;}
h4 { font-weight:500; font-size: 23px;}
h5 { font-weight:900; font-size: 17px;}
h6 { font-weight:900; font-size: 14px; text-transform: uppercase; color:#444;}
.collapse { margin:0!important;}
p, ul {
margin-bottom: 10px;
font-weight: normal;
font-size:14px;
line-height:1.6;
}
p.lead { font-size:17px; }
p.last { margin-bottom:0px;}
ul li {
margin-left:5px;
list-style-position: inside;
}
/* -------------------------------------
SIDEBAR
------------------------------------- */
ul.sidebar {
background:#ebebeb;
display:block;
list-style-type: none;
}
ul.sidebar li { display: block; margin:0;}
ul.sidebar li a {
text-decoration:none;
color: #666;
padding:10px 16px;
/* font-weight:bold; */
margin-right:10px;
/* text-align:center; */
cursor:pointer;
border-bottom: 1px solid #777777;
border-top: 1px solid #FFFFFF;
display:block;
margin:0;
}
ul.sidebar li a.last { border-bottom-width:0px;}
ul.sidebar li a h1,ul.sidebar li a h2,ul.sidebar li a h3,ul.sidebar li a h4,ul.sidebar li a h5,ul.sidebar li a h6,ul.sidebar li a p { margin-bottom:0!important;}
/* ---------------------------------------------------
RESPONSIVENESS
Nuke it from orbit. It's the only way to be sure.
------------------------------------------------------ */
/* Set a max-width, and make it display as block so it will automatically stretch to that width, but will also shrink down on a phone or something */
.container {
display:block!important;
max-width:600px!important;
margin:0 auto!important; /* makes it centered */
clear:both!important;
}
/* This should also be a block element, so that it will fill 100% of the .container */
.content {
padding:15px;
max-width:600px;
margin:0 auto;
display:block;
}
/* Let's make sure tables in the content area are 100% wide */
.content table { width: 100%; }
/* Odds and ends */
.column {
width: 300px;
float:left;
}
.column tr td { padding: 15px; }
.column-wrap {
padding:0!important;
margin:0 auto;
max-width:600px!important;
}
.column table { width:100%;}
.social .column {
width: 280px;
min-width: 279px;
float:left;
}
/* Be sure to place a .clear element after each set of columns, just to be safe */
.clear { display: block; clear: both; }
img.qrcode {
display: block;
margin-left: auto;
margin-right: auto;
}
/* -------------------------------------------
PHONE
For clients that support media queries.
Nothing fancy.
-------------------------------------------- */
@media only screen and (max-width: 600px) {
a[class="btn"] { display:block!important; margin-bottom:10px!important; background-image:none!important; margin-right:0!important;}
div[class="column"] { width: auto!important; float:none!important;}
table.social div[class="column"] {
width:auto!important;
}
}
</style>
</head>
<body bgcolor="#FFFFFF">
<!-- HEADER -->
<table class="head-wrap" bgcolor="#000000" width="100%">
<tr>
<td></td>
<td class="header container" >
<div class="content">
<table bgcolor="#000000">
<tr>
<td><img alt="Logo accueil" src="http://app.nightspree.com/assets/logo_accueil.png" /></td>
<td align="right"><h6 class="collapse"></h6></td>
</tr>
</table>
</div>
</td>
<td></td>
</tr>
</table><!-- /HEADER -->
<!-- BODY -->
<table class="body-wrap">
<tr>
<td></td>
<td class="container" bgcolor="#FFFFFF">
<div class="content">
<!DOCTYPE html>
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
<p>Hello,</p>
<p>You're receiving this e-mail because you requested a password reset for your user account (fel.bruno@gmail.com) at Nightspree app.</p>
<p><a href="nightspree://reset_password?password_reset_code=9197196061&email=fel.bruno@gmail.com">Click here</a> to open the Nightspree app and reset your password.</p>
<p>Or go to the password reset page within the app and enter the following reset code:</p>
<p><strong>9197196061</strong></p>
<p>Thanks for using Nightspree app and have a great day!</p>
<p>Nightspree team</p>
</body>
</html>
</div><!-- /content -->
</td>
<td></td>
</tr>
</table><!-- /BODY -->
<!-- FOOTER -->
<table class="footer-wrap">
<tr>
<td class="container">
<!-- content -->
<div class="content" width="100%" align="center">
<hr>
<br>
<h5><a href="nightspree://" style="color:#000000;">Nightspree</a></h5>
<a href="http://www.facebook.com/nightspree"><img alt="Facebook" height="30" src="http://app.nightspree.com/assets/facebook.png" width="30" /></a>
<a href="http://instagram.com/nightspree"><img alt="Instagram" height="30" src="http://app.nightspree.com/assets/instagram.png" width="30" /></a>
<a href="http://nightspree.com/"><img alt="Website" height="30" src="http://app.nightspree.com/assets/website.png" width="30" /></a>
<a href="http://www.twitter.com/nightspree_"><img alt="Twitter" height="30" src="http://app.nightspree.com/assets/twitter.png" width="30" /></a>
<a href="https://www.linkedin.com/company/nightspree"><img alt="Linkedin" height="30" src="http://app.nightspree.com/assets/linkedin.png" width="30" /></a>
</div><!-- /content -->
</td>
<td></td>
</tr>
</table><!-- /FOOTER -->
</body>
</html>
Completed 204 No Content in 63ms (ActiveRecord: 31.9ms)