如何获取Mandrill java api发送的邮件状态?

时间:2015-11-05 05:02:52

标签: java mandrill

我在使用lutung的mandrill java API时获取了一个内部服务器异常来获取邮件信息。这是我的代码。

public MandrillMessageInfo getMessageInfo(String id) {
MandrillApi mandrillApi = new MandrillApi("Your api key");
MandrillMessageInfo info = null;
try {
    info = mandrillApi.messages().info(id);
    log.debug("Message status-> Email {}, state: {}, timeOfSent: {} ", info.getEmail() ,info.getState(), TimeUtil.getLocalTimeString(info.getTs()));
} catch (Exception e) {
    log.debug("Exception occurs while getting message info for id: {}, exception is: {} ", id, e.getMessage());
    throw new MailServiceException(ErrorCodes.ERROR_INTERNAL_SERVER_ERROR, ErrorCodes.ERROR_MESSAGE_INTERNAL_SERVER_ERROR);
} 
return info;
}

1 个答案:

答案 0 :(得分:1)

我的代码中没有任何错误。如果您的API密钥正确,则此请求将返回错误的唯一原因是您提供了错误的ID。您可以通过直接在mandrill网站上发出消息/信息api请求来验证这一点,并使用"试一试"按钮https://mandrillapp.com/api/docs/messages.JSON.html#method=info并传递您通过程序调用提供的相同消息ID。

希望这有帮助,