As an afterthought, since you already fixed it. Here's a peice of advice that may or may not work for you. I am currently working with SMTP for work with a postfix mta system.
you may want to consider using threads and Thread::Queue. then you queue up your messages, create a pre-defined number of threads and just have them pull from the queue then join when they are done. Very fast very efficient.