Question

I need to send over 2000 mails and I am using Swift Mailer library for it.

We have own server and it has both SMTP and sendmail transports. I am using SMTP:

$transport = Swift_SmtpTransport::newInstance('localhost', 25);

All mails are send fine to few people, but I'm afraid that we will be banned when we send mass mail. I don't really know what means "banned" and how it looks like, but I'm afraid about the aftermath.

So, is it true, that such "ban" exists and how to implement mass mailing with Swift Mailer in a right way?

P.S.: My code looks like:

    // Create the Transport
    $transport = Swift_SmtpTransport::newInstance('localhost', 25);

    // Create the Mailer using your created Transport
    $mailer = Swift_Mailer::newInstance($transport);

    // Create a message
    $message = Swift_Message::newInstance($message_theme)
      ->setFrom(array($sender => $name))
      ->setTo($emails)
      ->setBody($message_text,"text/html")
      ;
    try {
        // Send the message
        $result = $mailer->send($message);
    }
    catch(Exception $e) {
        echo "Error: ".$e->getMessage();
    }
Was it helpful?

Solution

As I'm hoping you will not use this for spam!!!

Here are some things to do:

  • try to same different Emails (change name of the recipient in body)
  • send emails once every 3-4 seconds and not 100 emails/second - it should send 2000 emails in about 2-3 hours.

OTHER TIPS

Blacklisting/graylisting does indeed exist and there are some best practices you can implement to try to avoid these issues. For 2,000 emails, as long as your headers are legitimate, there is nothing fishy going on in your body text, and your recipients are on different domains, you should not run into this issue. However, as khomyakoshka mentions, the above code is incorrect and you should use a loop to send each email. This avoids exposing your entire mail list to each user.

Some additional best practices:

1) Swiftmailer offers plugins (http://swiftmailer.org/docs/plugins.html) that will help you send bulk email. Of particular note are the Throttler and AntiFlood plugins.

2) If you intend on modifying the contents of the mail to tailor to the recipient, consider using the Decorator plugin (also mentioned on the plugins page) for this task.

Hope these tips help.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top