小编kas*_*ar9的帖子

Rails 5 应用程序无法发送 sendgrid 电子邮件(Cloud 9 和 Heroku)

我已经检查了很多关于它的帖子,但仍然找不到解决方案..我认为它在部署中工作,但不,这些电子邮件没有发送..我只是将它们放入控制台。

我检查了我的 sendgrid 凭据,我使用 dotenv 添加了全局变量,所以我的代码可能有问题。

我还尝试使用该代码直接发送电子邮件:

require 'sendgrid-ruby'
include SendGrid

from = Email.new(email: 'test@example.com')
to = Email.new(email: 'test@example.com')
subject = 'Sending with SendGrid is Fun'
content = Content.new(type: 'text/plain', value: 'and easy to do anywhere, 
even with Ruby')
mail = Mail.new(from, subject, to, content)

sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
response = sg.client.mail._('send').post(request_body: mail.to_json)
puts response.status_code
puts response.body
puts response.parsed_body
puts response.headers
Run Code Online (Sandbox Code Playgroud)

没有运气:

puts response.status_code
400
 => nil 
2.3.4 :016 > puts response.body
{"errors":[{"message":"Invalid type. Expected: object, given: string.","field":"(root)","help":"http://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/errors.html#-Request-Body-Parameters"}]}
 => nil …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails heroku mailer

3
推荐指数
1
解决办法
922
查看次数

标签 统计

heroku ×1

mailer ×1

ruby-on-rails ×1