Oct 22

Swift mailer

I would like to drop here a couple of lines about Swift mailer.
If you are going to send message to the big number of email recepients it’s obviously you’ll need to write a batch script so it processes this in background. And it would be good to have something (mailer layer) that you can rely one and use for sending out tons of messages, newsletters or maybe even evil spam, why not.

So I’ve looked through Symfony forum and found a couple of posts which say to try SwiftMailer as a solution. And what is also important – there is already done swift bridge plugin for it: sfSwiftPlugin.

Swift is a fully OOP library for sending e-mails from PHP websites and applications. It does not rely on PHP’s native mail() function which is known for using high server resources when sending multiple emails. Instead, Swift communicates directly with an SMTP server or a MTA binary to send mail quickly and efficiently.

Early versions of Swift were comparable to PHPMailer. Swift has since evolved and matured into a fully-fledged object-oriented mailing solution. Compared with PHPMailer, the interface for Swift is both tighter and more intuitive. I genuinely belive that no other mailer comes close to Swift in terms of available features.

Swift supports event-driven plugins which offer you the opportunity to really take control of the library and set this mailer apart from everything else that’s out there. Over time, and from previous versions, the library has been steadily refactored and is now usable for more than just the blind sending of emails. It can compose RFC 2822 compliant messages for use elsewhere too. I’m looking at offering the reverse and parsing real emails into the message object format used in the library.

I refer you to swift doc so you can get more ideas how to built a site with it and which features it has http://www.swiftmailer.org/wikidocs/

Ok, so all you need to start it up is to add these lines to your batch script:

$swift =& new Swift(new Swift_Connection_SMTP(smtp_server_address));
$recipients =& new Swift_RecipientList();
$message =& new Swift_Message($email_subject, $email_body);
foreach ($addresses as $address) $recipients->addTo($address);
$swift->batchSend($message, $recipients, $from_email_address);

and go ahead with it! Interesting to know if someone has ever used Swift in production and what is performance and how it works for big amount of addresses. I can’t find such info on web.

Author: symfonian


March 5, 2008

I did try swift on a production server.
Trying to send around 2000 emails with batchSend failed mainly because of the fact that php was timing out before managing to send all of the emails.

I had to modify swift class a bit and use set_time_limit in order to overcome the issue. Of course I had to wait some time before all emails were send but other than that all good.

I guess an asynchronous batchSend method would be a charm for such cases.

October 26, 2008

If you are trying to send batch file is much better to fill a table with from,from_name,to and message fields.

Create a batch process wich read 5 rows each time and send the email using swift.

Then just set a crontab that runs periodically this batch process.

Comments RSS TrackBack Identifier URI

Leave a comment