Mailgun API: Batch Sending vs. Individual Calls
Stumbled onto this today, and felt it provided a pretty good summary/answer for my original question. I wanted to post this as an answer, in case anybody else has this question and hasn't found this Mailgun post. Straight from the horse's mouth, too. The nutshell version:
For PHP, at least, the SDK has a
Mailgun class, with a
BatchMessage() method. This actually handles the counting of recipients for you, so you can just queue up as many email addresses as you want (ie, more than 1k) and Mailgun will fire off to the API endpoint as needed. Pretty slick!
Here's their original wording, plus a link to the page.
Sending a message with Mailgun PHP SDK + Batch Message:
In addition to Message Builder, we have Batch Message. This class allows you to build a message and submit a template message in batches, up to 1,000 recipients per post. The benefit of using this class is that the recipients tally is monitored and will automatically submit the message to the endpoint when you've added the 1,000th recipient. This means you can build your message and begin iterating through your database. Forget about sending the message, the SDK will keep track of posting to the API when necessary.
// First, instantiate the SDK with your API credentials and define your domain. $mgClient = new Mailgun("key-example"); $domain = "example.com"; // Next, instantiate a Message Builder object from the SDK, pass in your sending domain. $batchMsg = $mgClient->BatchMessage($domain); // Define the from address. $batchMsg->setFromAddress("[email protected]", array("first"=>"Dwight", "last" => "Schrute")); // Define the subject. $batchMsg->setSubject("Help!"); // Define the body of the message. $batchMsg->setTextBody("The printer is on fire!"); // Next, let's add a few recipients to the batch job. $batchMsg->addToRecipient("[email protected]", array("first" => "pam", "last" => "Beesly")); $batchMsg->addToRecipient("[email protected]", array("first" => "Jim", "last" => "Halpert")); $batchMsg->addToRecipient("[email protected]", array("first" => "Andy", "last" => "Bernard")); // ...etc...etc... // After 1,000 recipeints, // Batch Message will automatically post your message to the messages endpoint. // Call finalize() to send any remaining recipients still in the buffer. $batchMsg->finalize();