Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batch Sending #26

Open
picks44 opened this issue Jun 3, 2016 · 4 comments
Open

Batch Sending #26

picks44 opened this issue Jun 3, 2016 · 4 comments

Comments

@picks44
Copy link

picks44 commented Jun 3, 2016

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

@tehplague
Copy link
Owner

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.

@Nyholm
Copy link
Collaborator

Nyholm commented Jun 3, 2016

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

@picks44
Copy link
Author

picks44 commented Jun 3, 2016

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

@gondo
Copy link

gondo commented Jun 7, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants