Skip to content

Batch Sending #26

Open
Open

Description

@picks44

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

Activity

  1. tehplague commented on Jun 3, 2016

    @tehplague
    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.

  2. Nyholm commented on Jun 3, 2016

    @Nyholm
    Collaborator

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

  3. picks44 commented on Jun 3, 2016

    @picks44
    Author

    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(['noreply@xxx.fr' => xxx.fr'])
                        ->setTo(['noreply@xxx.fr' => 'xxx.fr'])
                        ->setBcc($array)
                        ->setBody($body);
                    $this->mailer->send($mail);
                }
            } else {
                $mail = \Swift_Message::newInstance()
                    ->setContentType('text/html')
                    ->setSubject($subject)
                    ->setFrom(['noreply@xxx.fr' => 'xxx.fr'])
                    ->setTo(['noreply@xxxt.fr' => 'xxx.fr'])
                    ->setBcc($to)
                    ->setBody($body);
                $this->mailer->send($mail);
            }
        }
    

    with $to being an array [email] => name

  4. gondo commented on Jun 7, 2018

    @gondo

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions