我一直在尝试使用我的 rails 应用程序(开发中)设置 mailgun API,并且我正在使用 mailgun_rails gem,但是当尝试发送消息时,动作控制器给了我一个错误:
用户控制器中的 JSON::ParserError#create
765:“Mailgun Magnificent API”中出现意外令牌
提取的源码如下:
@user = User.create(user_params)
if @user.save
UserMailer.account_activation(@user).deliver_now
flash[:info] = "Please check your email to activate your account."
redirect_to root_url
我的 development.rb 有以下关于动作邮件的行:
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :mailgun
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.perform_deliveries = true
config.action_mailer.mailgun_settings = {
api_key: ENV['MAILGUN_API_KEY'],
domain: ENV['MAILGUN_DOMAIN']
}
config.action_mailer.perform_caching = false
我的 .rbenv-vars 文件中的环境如下所示:
MAILGUN_API_KEY=key-<<KEY>>
MAILGUN_DOMAIN=mg.<<MYDOMAIN>>.nl
mailgun 的所有域验证和 DNS 都已完成(并识别出我的 mailgun 本身)。
谁能帮我弄清楚出了什么问题?
编辑
我忘了包括我的终端跟踪:
Started POST "/signup" for 127.0.0.1 at 2017-09-11 22:03:58 +0200
ActiveRecord::SchemaMigration Load (0.3ms) SELECT `schema_migrations`.* FROM `schema_migrations`
Processing by UsersController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"<<TOKEN>>", "user"=>{"name"=>"Mailtest", "email"=>"<<EMAIL>>", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"}
(0.2ms) BEGIN
User Exists (0.3ms) SELECT 1 AS one FROM `users` WHERE `users`.`email` = '<<EMAIL>>' LIMIT 1
SQL (0.3ms) INSERT INTO `users` (`email`, `name`, `created_at`, `updated_at`, `password_digest`, `activation_digest`) VALUES ('<<EMAIL>>', 'Mailtest', '2017-09-11 20:03:59', '2017-09-11 20:03:59', '<<TOKEN>>', '<<TOKEN>>')
(1.9ms) COMMIT
(0.2ms) BEGIN
User Exists (0.3ms) SELECT 1 AS one FROM `users` WHERE `users`.`email` = '<<EMAIL>>' AND (`users`.`id` != 17) LIMIT 1
(0.2ms) COMMIT
Rendering user_mailer/account_activation.html.erb within layouts/mailer
Rendered user_mailer/account_activation.html.erb within layouts/mailer (5.6ms)
Rendering user_mailer/account_activation.text.erb within layouts/mailer
Rendered user_mailer/account_activation.text.erb within layouts/mailer (0.6ms)
UserMailer#account_activation: processed outbound mail in 222.3ms
Sent mail to <<EMAIL>> (1149.7ms)
Date: Mon, 11 Sep 2017 22:03:59 +0200
From: noreply@<<DOMAIN>>.nl
To: <<EMAIL>>
Message-ID: <<ID>>
Subject: Account activation
Mime-Version: 1.0
Content-Type: multipart/alternative;
boundary="--==_mimepart_59b6ec2f9d9da_4dd63ff8ffd4f034650e4";
charset=UTF-8
Content-Transfer-Encoding: 7bit
----==_mimepart_59b6ec2f9d9da_4dd63ff8ffd4f034650e4
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
Hi Mailtest,
Welcome to the <<DOMAIN>>! Click on the link below to activate your account:
<<ACTIVATION LINK>>
----==_mimepart_59b6ec2f9d9da_4dd63ff8ffd4f034650e4
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
/* Email styles need to be inline */
</style>
</head>
<body>
<h1><<DOMAIN>></h1>
<p>Hi Mailtest,</p>
<p>
Welcome to the <<DOMAIN>>! Click on the link below to activate your account:
</p>
<a href="<<ACTIVATION LINK>>">Activate</a>
</body>
</html>
----==_mimepart_59b6ec2f9d9da_4dd63ff8ffd4f034650e4--
Completed 500 Internal Server Error in 1589ms (ActiveRecord: 5.4ms)
JSON::ParserError (765: unexpected token at 'Mailgun Magnificent API')