我在 Mandrill API 上通过 Jersey 客户端发送消息时遇到问题。我使用 Jersey 客户端如下:
ClientBuilder.newClient()
.register(JacksonJsonProvider.class)
.target(“https://mandrillapp.com/api/1.0/messages/send.json”)
.request(MediaType.APPLICATION_JSON_TYPE)
.post(Entity.json(methodEntity));
在下面您可以看到记录的 API 请求的 header 、方法和内容。
POST https://mandrillapp.com/api/1.0/messages/send.json
Accept: application/json
Content-Type: application/json
{"message":{"subject":"Hello World!","text":"Really, Im just saying hi from Mandrill!","to":[{"email":"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="335e524150565f734b4b4b4b1d505c5e" rel="noreferrer noopener nofollow">[email protected]</a>","name":"Marcel cccc","type":"to"}],"headers":{},"tags":["test"],"from_email":"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="95fcfbf3fad5edededededbbf6faf8" rel="noreferrer noopener nofollow">[email protected]</a>","auto_text":true,"preserve_recipients":false},"async":false,"key":"EWIBVEIOVBVOIEBWIOVEB"}
为了响应此请求,我不断收到以下消息:
[{"email":"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="234e425140464f637b7b7b7b0d404c4e" rel="noreferrer noopener nofollow">[email protected]</a>","status":"rejected","_id":"0ea5e40fc2f3413ba85b765acdc5f17a","reject_reason":"invalid-sender"}]
我不知道问题是什么,从一些帖子中我发现我必须使用 UTF-8 来编码我的消息和 header 。但将编码设置为 UTF-8 并没有多大作用。否则,有效负载对我来说似乎很好,而且我在论坛上发现无效的发件人可能意味着任何其他类型的问题(不仅仅是令人悲伤的无效发件人)。
最佳答案
我遇到了完全相同的问题
"reject_reason":"invalid-sender"
您可能已经检查过类似的问题 Mandrill “reject_reason”: “invalid-sender”
如果有帮助,请尝试一下。我发现您的请求中还缺少 header 参数
e.g. User-Agent: Mandrill-myclient/1.0
请尝试将此参数添加到您的 Jersey 客户端设置中,如下所示:
ClientBuilder.newClient()
.register(JacksonJsonProvider.class)
.target(“https://mandrillapp.com/api/1.0/messages/send.json”)
.request(MediaType.APPLICATION_JSON_TYPE)
.header("User-Agent", "Mandrill-myclient/1.0")
.post(Entity.json(methodEntity));
有帮助吗?
关于jersey - Mandrill API 发送请求时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26141535/