简体   繁体   English

如何在山d中取消预定的电子邮件?

[英]How to cancel a scheduled email in mandrill?

I am using https://github.com/abishekrsrikaanth/mailto package to handle my emails in mandrill. 我正在使用https://github.com/abishekrsrikaanth/mailto软件包在mandrill中处理我的电子邮件。 The package has a method to schedule an email like this. 该程序包提供了一种计划电子邮件的方法。

$timestamp = new DateTime('+1 hour');
$mandrill = MailTo::Mandrill();
$mandrill->addRecipient($email, $name)
         ->setFrom($email, $name)
         ->setHtml($html)
         ->setText($text)
         ->setSubject($subject)
         ->send($timestamp);

But I can't find a way to cancel a scheduled email. 但是我找不到取消预定电子邮件的方法。 I read this docs https://mandrillapp.com/api/docs/messages.JSON.html#method=cancel-scheduled 我阅读了这份文档https://mandrillapp.com/api/docs/messages.JSON.html#method=cancel-scheduled

Request JSON 请求JSON

 {
    "key": "example key",
    "id": null
} 

but I don't know how to implement this. 但我不知道如何实现。 Does anyone can help me with this? 有人可以帮我吗?

You can use the official Mandrill PHP SDK as the method to cancel a scheduled email is not implemented in the MailTo package. 您可以使用官方的Mandrill PHP SDK,因为MailTo包中未实现取消计划的电子邮件的方法。

<?php
try {
    $mandrill = new Mandrill('YOUR_API_KEY');
    $id = 'YOUR-MESSAGE-ID'; // id of scheduled message to be cancelled
    $result = $mandrill->messages->cancelScheduled($id);
    print_r($result);
} catch(Mandrill_Error $e) {
    echo 'A mandrill error occurred: ' . get_class($e) . ' - ' . $e->getMessage();
    throw $e;
}
?>

Here is the information on that https://mandrillapp.com/api/docs/messages.php.html#method-cancel-scheduled 这是关于https://mandrillapp.com/api/docs/messages.php.html#method-cancel-scheduled的信息

You simply need to pass the message id and it will be removed from the scheduled message queue. 您只需要传递消息ID,它将从计划的消息队列中删除。 You will most probably have the message id in the response of the schedule call. 您很可能在计划调用的响应中具有消息ID。

Here are the details on setting the SDK up https://mandrillapp.com/api/docs/index.php.html 以下是有关设置SDK的详细信息https://mandrillapp.com/api/docs/index.php.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM