views:

1304

answers:

8

I need to be able to periodically send email alerts to subscribed users. PHP seems to struggle with sending one message, so I'm looking for good alternatives.

Any language will do, if the implementation is fast enough. The amount of mails sent will eventually be in the thousands.

If purchasing licensed software can be avoided, so much the better.

+1  A: 

We have various applications writing to an email queue in a database table, and a .Net Windows Service polling that table to compose the emails and send out through our mail server.

We do up to 1000 emails per minute...

Mark Glorie
@mark: I've posted a question about mass emailing. You seem to have experience with this. Could you have a look at http://stackoverflow.com/questions/162149/avoid-being-blocked-by-web-mail-companies-for-massbulk-emailing please
Johannes
Mark: What SMTP server do you use to do that?
greg7gkb
I work at an ISP (Internet Provider), we have our own SMTP servers...
Mark Glorie
+1  A: 

For Java, there is http://java.sun.com/products/javamail/ I've used it in an application. Pretty easy to set up and use.

In Ruby it is extremely simple, but I haven't used it so can't say anything about performance. http://snippets.dzone.com/posts/show/2362

That said... I doubt PHP itself would be too slow to send mails. Perhaps you have some bottleneck in your application?

Lars Westergren
A: 

There is a dos based command line tool called blat that you can download and send emails very easily

pappes
+1  A: 

Would just like to mention that in my previous job we created a mass emailer solution in PHP that worked great, so I don't see why you would rule it out completely :)

Torbjørn
Based on a couple of comments here I'm starting to think that my problems with PHP had more to do with the server than the language itself. I'll see how it performs on the new box compared to Java and Ruby.
kari.patila
+1  A: 

smtplib in python is a doddle to set up and a very clean API.

Simon
Thanks, I'll look into it. Python would be the preferred language since I already have apps running on it.
kari.patila
+1  A: 

One thing you could do is change the focus of the question to the underlying mail software. For instance, if I wanted to send a ton of emails, I would use any language to write them out in BSMTP format, which basically looks like simple SMTP client commands. Something like:

MAIL FROM:<[email protected]>
RCPT TO:<[email protected]>
DATA
From: Me <[email protected]>
To: You <[email protected]>
Subject: test email

This is the body of the test email I'm sending
.

Then I would feed the BSMTP files through exim:

cat *.bsmtp | exim -bS

This essentially removes the delay in sending the emails from you program and places the burden on exim (which as an MTA is better equipped to handle it).

Once you get the basics, there are a ton of things you can modify to make more efficient. For instance, if your emails aren't customized, you can pre-optimize by putting all recipients to the same domain into the same BSMTP file:

MAIL FROM:<[email protected]>
RCPT TO:<[email protected]>
RCPT TO:<[email protected]>
RCPT TO:<[email protected]>
RCPT TO:<[email protected]>
DATA
From: Me <[email protected]>
To: Me <[email protected]>
Subject: test email

This is the body of the test email I'm sending
.

You also then get a ton of wiggle room in how you optimize the MTA itself to send the mail (for instance, it'll automatically handle parallel deliveries, deliveries of email to the same mail server down the same TCP connection, etc).

With respect to doing it in code, we used to have a drop in perl library that helped us do this stuff. Essentially you fed it the emails and the addresses and it would fork off calls to the mail server as needed. It was configurable in how many parallel sessions it would allow, and it also monitored the load on the server and would throttle back if the load crossed a user-configurable threshold.

jj33
+2  A: 

http://stackoverflow.com/questions/17609/email-queueing-in-php#17696 - the short version - Pear's Mail_Queue. I've been using this to send out 30-50,000+ mails per day or more (a few days a week) without problems for more than a year.

Alister Bulman
A: 

I use a program called e-Campaign that reads in CSV files. If you have to do it programmatically, then you may want to build in a waiting technique so you don't try to send 10,000 emails all at once. With e-Campaign you can choose how many emails to send at a time and put a break time between those batches. It's still very fast but doesn't cause overload issues with the server.

Joe Philllips