4

I'm writing a Java mass emailer application to send out emails to send between 50,000 to 100,000 a day to users.

The current plan is to delegate the sending to delegate to sendmail (on the local unix server).

From our testing sendmail is sending a maximum of 5 emails per second.

Would JavaMail be a faster option?

Does anyone know what a faster way to send emails. We want to get this process out as quick as possible.

Edit: BTW, a pdf will be attached too

WellieeGee
  • 312
  • 1
  • 4
  • 13
  • Are you using Runtime.exec(..) currently? – Amir Afghani Nov 22 '09 at 21:50
  • You're probably not going to make the process 'go faster' by just changing the program you're using to send emails. To see any significant speed up, you're going to need to do something to parallelize the process so you can do it across multiple machines at the same time. – Nate Nov 22 '09 at 23:10
  • Found this (http://stackoverflow.com/questions/1325482/sendmail-vs-smtp/1325883#1325883) recommending sendmail. – WellieeGee Nov 23 '09 at 03:02

4 Answers4

6

You're not comparing like with like. JavaMail talks SMTP to hand off to the nearest mail server. Sendmail is a Mail Transfer agent responsible for routing emails to their destination.

A common setup is a java application using JavaMail to relay email via SMTP to a Sendmail server. The two are not competitors, they're used together. A sendmail server should be able to accept deliveries from javamail faster than any java application can produce them, but then it delivers them asynchronously at its own rate.

skaffman
  • 398,947
  • 96
  • 818
  • 769
4

This might be a little too old, but I just managed to get javamail and sendmail to work together. It's actually super easy and I felt stupid for not getting it done faster...

Let's ignore sendmail for a bit here. How can we send an e-mail through javamail? There are tons of tutorials online, but here's how it's done:

  1. Create your session with the appropriate authenticator;
  2. Create your MimeMessage object (here's where you add all your recipient addresses);
  3. Call Transport.send() with your message.

What if your SMTP server only sends emails up to 100 recipients (like mine)? That's when sendmail comes into play. You can think about sendmail as your own SMTP server. So install it first. If you're running Ubuntu (like me), just do:

sudo apt-get install sendmail

The installation ends pretty quickly. After that, sendmail is ready to be used. I didn't bother configuring any type of authentication or whatsoever, but it's probably a good idea to do so if your server will have a public IP on the internet. Now, instead of pointing your java code (that uses javamail) to your SMTP server, just point it to localhost (or whatever machine you just installed sendmail).

You can even test your sendmail installation with your regular mail client (thunderbird, outlook, windows mail or whatever floats your boat). Just configure your SMTP server to the machine you installed sendmail. Guess what? It works!

Just don't use this to send emails to the entire world... ;)

ryanprayogo
  • 11,587
  • 11
  • 51
  • 66
Andre
  • 3,874
  • 3
  • 35
  • 50
1

First of all, I suppose this is for legitimate reasons and not spamming?

Sendmail is very, very fast for sending emails. What is not so fast is the DNS lookups needed to locate the mailservers for the domain - you need to do a MX query for each - and that would fit fine with the 5 messages pr second you report.

When that is said, you would probably be best off with standard high-performance mailing list software where you construct the message with javamail and tell the mailing list software to send it to everybody. Also ally with e.g. Google Mail as they scale well, to actually get them all sent. Google Apps for Java can allow you to send from within the Google cloud.

Back in ancient history when I worked with that Majordomo worked fine with sendmail. ezmlm works well with qmail (but is probably abandoned by now) and I think mjmlm works well with postfix.

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347
  • Yes it is for legit reasons. Institution sending emails to employees with a customised pdf attachment. The attachment and recipient details comes from an Oracle database, so Google Apps integration isn't possible. (shame as we have a partnership with Google). – WellieeGee Nov 22 '09 at 23:06
1

If we use Tranport.send() - Static method, in Java mailer for sending the mails,this method does the handshaking, for each of the email address present in the list. (Handshaking is: Request from Client -> Response from the server -> Acknowledgement. ), i.e. each time it closes the connection with the SMTP mail server. Here is way to increase the performance.., by which we can do handshaking only one time, and it greatly reduces the SMTP traffic. And send the mail to all recipients in one shot, Pl refer SCR#A for SMTP traffic for this scenario. Here is the code for reference,

Instead of,

Transport.send(msg);

We should use below piece of code,

                            msg.saveChanges(); // implicit with Transport.send()
                            Transport tr = session.getTransport("smtp");
                            tr.connect(smtphost, username, password);
                            msg.saveChanges();   // don't forget this
                            tr.sendMessage(msg, msg.getAllRecipients());
                            tr.close();

For sending bulk mails.

Here you can see the network traffic using wire shark tool..

What is needed, to setup this with a Mail server. -->A local m/c installed with Wire shark tool and Apache tomcat 6.0 and it should be able to ping your mail server say relay.abcxyz.com

Now run the test bed for both the cases.

Priyank Jain
  • 97
  • 2
  • 9