Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

JavaMailing in bulk

8 views
Skip to first unread message

Andy J

unread,
Nov 20, 2001, 12:43:55 PM11/20/01
to
Exchange is throwing a MessagingException after sending a few emails
on one session:

Part of my application emails lots of different emails to different
people at approximately the same time in different threads. I am
using JavaMail 1.2 using the default SMTP implementation to Exchange
5.5.

The system creates 1 session and uses the session's
transport.sendMessage() to send each message. It synchronizes to
ensure that it waits until the previous sendMessage() has been
acknowledged by update(), or sendMessage() has thrown an Exception.

After a few emails (say 10) sendMessage() throws a MessageException
with no description:

javax.mail.MessagingException:
at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:879)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:599)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:319)
at com.vrisko.emailalert.Emailer.email(Emailer.java:609)
...

After that, all sendMessage()'s using that session throw a
MessageException:

javax.mail.MessagingException: Can't send command to SMTP host;
nested exception is:
java.net.SocketException: Connection aborted by peer: socket write
error
at com.sun.mail.smtp.SMTPTransport.sendCommand(SMTPTransport.java:909)
at com.sun.mail.smtp.SMTPTransport.sendCommand(SMTPTransport.java:897)
at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:874)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:599)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:319)
at com.vrisko.emailalert.Emailer.email(Emailer.java:609)
...

Does anybody know what might be causing these Exceptions? Should I be
reusing the same session message after message?

Should I open a new session each time, or is that going to run into
problems or have big overheads? bearing in mind that approx 500 emails
could be send within approx 20mins of each other.

Finally, should I create a session pool, replacing broken session with
new ones - I'd prefer that no Exceptions are thrown at all though.

Cheers for any help,
Andy.

Kenny MacLeod

unread,
Nov 20, 2001, 1:07:38 PM11/20/01
to
is it possible that your SMTP server has a spam-resistent filter that
rejects a large number of emails sent from the same place in rapid
succession?

Not that I'm suggestng that you're sending spam, of ouse :-)


"Andy J" <a_jef...@yahoo.co.uk> wrote in message
news:afb02cbb.01112...@posting.google.com...

G Winstanley

unread,
Nov 21, 2001, 7:40:27 AM11/21/01
to
On 20 Nov 2001 09:43:55 -0800, the cup of a_jef...@yahoo.co.uk (Andy J)
overfloweth with the following:

> Exchange is throwing a MessagingException after sending a few emails
> on one session:
>
> Part of my application emails lots of different emails to different
> people at approximately the same time in different threads. I am
> using JavaMail 1.2 using the default SMTP implementation to Exchange
> 5.5.
>

...SNIP...


> Does anybody know what might be causing these Exceptions? Should I be
> reusing the same session message after message?
>
> Should I open a new session each time, or is that going to run into
> problems or have big overheads? bearing in mind that approx 500 emails
> could be send within approx 20mins of each other.
>
> Finally, should I create a session pool, replacing broken session with
> new ones - I'd prefer that no Exceptions are thrown at all though.
>
> Cheers for any help,
> Andy.

You might just have to face the fact that email servers are only designed to
cope with a certain volume of email within the certain amount of time. Do
you *have* to get this number of emails out so quickly, or can you
conceivable send them serially and have a longer delay between first and
last?

I worked on an online Formula1 fantasy game this year which had to send out
several thousand emails after each race, in addition to dealing with new
registrations etc. and the serial email sending worked perfectly, with no
mail loss and the whole sending only took about 1½-2 hours each time which
was done overnight when traffic was lower.

By getting many threads to simultaneously access the server you are simply
drowning it in requests and stopping it performing. Try pacing yourself
instead and allowing it to do it's job. Also, if the emails are not all
personalised try sending a single email with multiple "To" addresses. This
makes the conversation with the server quicker initially.

Stan

AV

unread,
Nov 21, 2001, 8:40:03 AM11/21/01
to
Mailing speed is very dependant on smtp relay settings.
Well tuned powerful relay can send out emails within ten(s)
of milliseconds (after receiving from mail application).
The main question is "who is bottleneck ?".
Low-level smtp mailer can send email to relay
(deliver to relay) within
several milliseconds, JavaMail - within 30-80 ms.
Bad / slow relay will send several mails fast but
than starts responding within seconds (or
just refuse/brake connections). Any linux distro
comes with good smtp relay. I have no idea how
tuneable and reliable MS relays are...

AlexV


"G Winstanley" <stan...@hotmail.com> wrote in message
news:m65nvt4s0sdrhk30e...@4ax.com...

G Winstanley

unread,
Nov 21, 2001, 11:56:11 AM11/21/01
to
On Wed, 21 Nov 2001 08:40:03 -0500, the cup of "AV"
<avek_...@videotron.ca> overfloweth with the following:

> Mailing speed is very dependant on smtp relay settings.
> Well tuned powerful relay can send out emails within ten(s)
> of milliseconds (after receiving from mail application).
> The main question is "who is bottleneck ?".
> Low-level smtp mailer can send email to relay
> (deliver to relay) within
> several milliseconds, JavaMail - within 30-80 ms.
> Bad / slow relay will send several mails fast but
> than starts responding within seconds (or
> just refuse/brake connections). Any linux distro
> comes with good smtp relay. I have no idea how
> tuneable and reliable MS relays are...
>
> AlexV
>

Couldn't agree more. The settings are paramount, especially when it comes to
DNS lookups for address validation etc. Whilst I'm no email expert I've seen
many different setups with wildly differing statistics on transfer/handshake
rates. Possibly just coincidence, but generally the mail servers I've used
which have been slow have been Microsoft-based, but I imagine this is almost
entirely down to bad configuration rather than feature-set.

Stan

Andy J

unread,
Nov 26, 2001, 10:49:42 AM11/26/01
to
G Winstanley <stan...@hotmail.com> wrote in message news:
> On 20 Nov 2001 09:43:55 -0800, the cup of a_jef...@yahoo.co.uk (Andy J)
> overfloweth with the following:
>
> > Exchange is throwing a MessagingException after sending a few emails
> > on one session:

Though testing, I found that the answer was quite simple - the SMTP had
simply timed the session out after a couple mins of inactivity, and just
"forgot" to tell me it was a timeout error.

> By getting many threads to simultaneously access the server you are simply
> drowning it in requests and stopping it performing. Try pacing yourself
> instead and allowing it to do it's job. Also, if the emails are not all
> personalised try sending a single email with multiple "To" addresses. This
> makes the conversation with the server quicker initially.

I wasn't clear in my original message - the multiple threads were generating
the email content (which could take anything up to around 4 mins as it
involved talking over the internet) - but then were synchronized to ensure
that only one transport.sendMessage() was executed at one time, waiting for
acknowledgment through (messageDelivered() etc) before allowing the next
transport.sendMessage().

I'd like to speed up this process up by placing the generated Message into
a queue that is serviced by a Thread(s) dedicated to emailing, but have a
couple of questions:

Do I have to wait before acknowledgement from the SMTP server via
messageDelivered() before sending the next?

Can I have multiple sessions open (in different threads) using the same
username and send messages with no synchronization?

Can I send a Message generated from one session (new MimePart(session)) on
another session's transport?

Is there a keep-alive on SMTP so I can ensure that a timeout doesn't occur?

Cheers,
Andy.

0 new messages