Jay Marz
Jay Marz

Reputation: 1912

How to cancel a scheduled email in mandrill?

I am using https://github.com/abishekrsrikaanth/mailto package to handle my emails in 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

Request JSON

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

but I don't know how to implement this. Does anyone can help me with this?

Upvotes: 2

Views: 1561

Answers (1)

Noman Ur Rehman
Noman Ur Rehman

Reputation: 6957

You can use the official Mandrill PHP SDK as the method to cancel a scheduled email is not implemented in the MailTo package.

<?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

You simply need to pass the message id and it will be removed from the scheduled message queue. You will most probably have the message id in the response of the schedule call.

Here are the details on setting the SDK up https://mandrillapp.com/api/docs/index.php.html

Upvotes: 3

Related Questions