Search code examples
javasmtpjakarta-mail

javax mail exceeding sending limit : SMTPSendFailedException


I am trying to send 500+ emails via a for loop with javaxmail - no Spam, the email adresses are known and certified.

The aim was to have a little time delay (1 - 5 sec) between sending (Thread.sleep(...)), so the mails do not automatically go into the Spam Folder. But after testing some time by sending it to my own email address, I keep getting this error :

com.sun.mail.smtp.SMTPSendFailedException: 554 5.7.0 Your message could not be sent. The limit on the number of allowed outgoing messages was exceeded. Try again later.

I am using our own smtp Server.

    properties.setProperty("mail.smtp.auth", "true");
    properties.setProperty("mail.smtp.host", host);
    properties.setProperty("mail.smtp.port", "25");

I'd like to know how long the time span for "try again later" is?

Does anyone know the limit?

Also any suggestions how to avoid this would be helpful.


Solution

  • In most of the cases you should try to avoid those mass mail sending (spam filters are pretty discriminative on large amount of mails no matter what), but in your case there is a simpler answer. Distributed mail processing is preferred, with time based limit rates etc.

    The problem You likely have is that (as the errormsg says) you try to exceed the limit of your outgoing mail number. (You could get further information by examining the getCommand and getReturnCode.) If you are using POSTFIX with policyd here is an example of the outgoing mail limit configuration:

    http://wiki.policyd.org/accounting?s[]=limit

    You could "fix" this problem by reconfiguring your SMTP server. Altough my recommendation is (to avoid getting on block list) to split up your whole email sending process:

    • create a(n hourly?) cron job that invokes a mail sender process
    • in the process you should have a limit (eg: 100) and try to send the mails
    • if the mail is sent it is OK else the next time the cron is running you could try to resend it (use a maximum number for retry with some log information)

    Those limits are for your own safety in most of the cases. Those prevent you from getting onto blacklists if a software bug occures etc.