title: SwiftMailer library performing slow
body: <p>I'm trying to implement swiftmailer into this mailing system. my client has about 300k active emails that need to be sent on a semi regular basis. the system was originally configured for sendmail and php's mail() function. I've since installed the latest version of postfix.</p>
  
  <p>it may be my expectations were way too high but i was under the impression this thing can put a lot of emails into the queue FAST, which is exactly what i need. all the rate handling and throttling is done on the postfix side, so being able to queue them as fast as my postfix settings can handle would be great.</p>
  
  <p>while i could implement methods to insert the contact directly into the queue, i'd rather limit the input of emails going into the queue based on various options such as global send rates for the smtp server.</p>
  
  <p>the code below is just something basic to test. it loops through 30 separate mailing smtp accounts, each with it's own rate properties. i'm trying to pull the max amount of emails out of the db per cron, then send then all using <code>batchsend()</code>, then loop to the next smtp account, send max, etc.. </p>
  
  <p>technically it does work, however it's really slow. at a rate of 60/min per smtp account, it takes about 15-20 seconds each which obviously will not work and not at all what i had expected.</p>
  
  <p>is there something really obvious about why this would send so slow? the smtp servers appear to be fine, no overload or anything like that. no postfix errors, nothing obvious. </p>
  
  <p>once the emails make it to the queue, i let postfix work it's magic. it's getting it into the queue at a reasonable rate that's become difficult. i know swiftmailer is a magic solution to all my problems, but i'm sure it should be sending quicker than it is. any ideas or suggestions?</p>
  
  <pre><code>$query = "SELECT * FROM `smtp`";
      $result = mysql_query($query) or die(mysql_error());
      $num_rows1 = mysql_num_rows($result);
      while($row = mysql_fetch_array($result)){
          $smtp = $row['ip'];
          $login = $row['user'];
          $pass = $row['pass'];
          $smtp_domain = $row['domain'];   
  
      $querya = "SELECT * FROM `mailer_lists` ml JOIN `mailer_controller` mc ON ml.project_name = mc.project_name LIMIT ".$global_limit."";
      $resulta = mysql_query($querya) or die(mysql_error());
      $num_rows2 = mysql_num_rows($resulta);
  
      // quickly check if any mail returned query
      if ($num_rows2 &lt; 1){
          mysql_close($connection);
          echo "Nothing to mail... \n";
          die();
          }
  
      while($rowa = mysql_fetch_array($resulta)){
          $email[] = $rowa['email'];
          $project_name = $rowa['project_name'];
          $from_name = $rowa['from_name'];
          $subject = $rowa['subject'];
          $body = $rowa['body'];
          $from = array($spun_from_email =&gt; $spun_from_name);
      }    
  
      require_once 'swift/swift_required.php';
          $transport = Swift_SmtpTransport::newInstance(''.$smtp.'', 25)
            -&gt;setUsername($login)
            -&gt;setPassword($pass)
            ;
          $mailer = Swift_Mailer::newInstance($transport);
          $message = Swift_Message::newInstance()
            -&gt;setSubject($subject)
            -&gt;setFrom($from)
           // -&gt;addPart('add part message', 'text/html')
           // -&gt;attach(Swift_Attachment::fromPath(''))
            -&gt;setTo($email)
            -&gt;setBody($body)
          ;
          $mailout = $mailer-&gt;batchSend($message);
           // -&gt;addPart('add part message', 'text/html')
           // -&gt;attach(Swift_Attachment::fromPath(''))
            ;  
  
  
              $queryb = "DELETE FROM `mailer_lists` WHERE `project_name` = '".$project_name."' AND `email` = '".implode('\' OR `email` = \'',$email)."'";  
              $resultb = mysql_query($queryb) or die(mysql_error());
              $c++;
              echo "sent $num_rows1 emails to smtp $c \n";
          }
  </code></pre>