swiftmailer-mailgun-bundle
swiftmailer-mailgun-bundle copied to clipboard
Batch Sending
How can I achieve MailGun Batch Sending within Symfony2 and this bundle ?
Currently, you have to specify multiple recipients and pass an X-Mailgun-Recipient-Variables
header containing JSON-encoded recipient variables that can be used in your e-mail.
Unfortunately neither this bundle nor Swiftmailer itself can assist you here as we can only implement the lowest common denominator of all features supported by both Swiftmailer and Mailgun. The Swiftmailer developers themselves recommend sending each email individually (see http://swiftmailer.org/docs/sending.html#sending-emails-in-batch). But of course they do not use any of Mailgun's specialized capabilities in their code.
That is a good question. We should document that answer in the readme.
Thank you, that helps a lot! In the meantime I've develop my own "kind-of-batch" sending method in my mailer service
public function sendMessage($subject, $to, $body)
{
if (count($to) >= 1000) {
$arrays = array_chunk($to, 1000, true);
foreach ($arrays as $array) {
$mail = \Swift_Message::newInstance()
->setContentType('text/html')
->setSubject($subject)
->setFrom(['[email protected]' => xxx.fr'])
->setTo(['[email protected]' => 'xxx.fr'])
->setBcc($array)
->setBody($body);
$this->mailer->send($mail);
}
} else {
$mail = \Swift_Message::newInstance()
->setContentType('text/html')
->setSubject($subject)
->setFrom(['[email protected]' => 'xxx.fr'])
->setTo(['[email protected]' => 'xxx.fr'])
->setBcc($to)
->setBody($body);
$this->mailer->send($mail);
}
}
with $to
being an array [email] => name
X-Mailgun-Recipient-Variables
header with recipients doesn't work
i'm unsuccessfully trying to get an official answer from mailgun support