swiftmailer-mailgun-bundle icon indicating copy to clipboard operation
swiftmailer-mailgun-bundle copied to clipboard

Batch Sending

Open picks44 opened this issue 8 years ago • 4 comments

How can I achieve MailGun Batch Sending within Symfony2 and this bundle ?

picks44 avatar Jun 03 '16 06:06 picks44

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.

tehplague avatar Jun 03 '16 06:06 tehplague

That is a good question. We should document that answer in the readme.

Nyholm avatar Jun 03 '16 06:06 Nyholm

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

picks44 avatar Jun 03 '16 06:06 picks44

X-Mailgun-Recipient-Variables header with recipients doesn't work i'm unsuccessfully trying to get an official answer from mailgun support

gondo avatar Jun 07 '18 16:06 gondo