gpt4 book ai didi

ruby mailgun 发送邮件失败,出现 400 错误请求

转载 作者:数据小太阳 更新时间:2023-10-29 07:33:34 25 4
gpt4 key购买 nike

我正在尝试使用 ruby​​ 的 mailgun API。我做的第一件事是注册一个帐户。我激活了 api_key 和沙箱域。然后,我将自己的电子邮件添加到沙盒域中的授权收件人。我在文档中所做的完全一样:

def send_simple_message
RestClient.post "https://api:key-mykey"\
"@api.mailgun.net/v3/sandboxe5148e9bfa2d4e99a1b02d237a8546fe.mailgun.org/messages",
:from => "Excited User <postmaster@sandboxe5148e9bfa2d4e99a1b02d237a8546fe.mailgun.org>",
:to => "my@email.com, postmaster@sandboxe5148e9bfa2d4e99a1b02d237a8546fe.mailgun.org",
:subject => "Hello",
:text => "Testing some Mailgun awesomness!",
:multipart => true
end

send_simple_message

但它总是返回 400 错误请求,这是来自终端的跟踪:

/home/ys/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rest-client-2.0.0/lib/restclient/abstract_response.rb:223:in `exception_with_response': 400 Bad Request (RestClient::BadRequest)
from /home/ys/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rest-client-2.0.0/lib/restclient/abstract_response.rb:103:in `return!'
from /home/ys/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rest-client-2.0.0/lib/restclient/request.rb:860:in `process_result'
from /home/ys/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rest-client-2.0.0/lib/restclient/request.rb:776:in `block in transmit'
from /home/ys/.rbenv/versions/2.3.1/lib/ruby/2.3.0/net/http.rb:853:in `start'
from /home/ys/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rest-client-2.0.0/lib/restclient/request.rb:766:in `transmit'
from /home/ys/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rest-client-2.0.0/lib/restclient/request.rb:215:in `execute'
from /home/ys/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rest-client-2.0.0/lib/restclient/request.rb:52:in `execute'
from /home/ys/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rest-client-2.0.0/lib/restclient.rb:71:in `post'
from mailgunner.rb:24:in `send_simple_message'
from mailgunner.rb:33:in `<main>'

我这里做错了什么?我安装了 rest-client gem,所以我认为我的注册有问题还是什么?

最佳答案

我遇到了类似的问题,在这里看到了文档: https://github.com/rest-client/rest-client (在异常(exception)部分)他们用救援包围了 RestClient.post。我把它打印出来了:

 def send_simple_message
begin
RestClient.post ...
rescue RestClient::ExceptionWithResponse => e
puts e.response
end
end

然后我得到一个错误字符串:

{"message": "'from' parameter is not a valid address. please check documentation"}

然后看到在我的测试中我在 from 字段中有一个错误:

:from => "Test <alert@mg.example.com", # missing '>' at the end 

也许您可以使用类似的方法来解决您的问题。

关于ruby mailgun 发送邮件失败,出现 400 错误请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38388514/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com