Javax.mail.SendException,,, Connection timed out

Hi

Was wondering if anyone could help me out to sort a problem I'm facing with a mail-application I'm configuring.

I have a mailprogram that are gonna send all from 100 to a 1000 mail. This is business related, and not spam,,,so that is said.

What happens is, that when sendinging mail, once in a while I get the Exception(I've commented out some of the classes and mailserver, because it has sensetive customers name in it):

javax.mail.SendFailedException: Sending failed;

nested exception is:

javax.mail.MessagingException: Could not connect to SMTP host: ***.***.**.**, port: 25;

nested exception is:

java.net.ConnectException: Connection timed out: connect

at javax.mail.Transport.send0(Transport.java:219)

at javax.mail.Transport.send(Transport.java:81)

at no.*****(SendCampaign.java:131)

at no.******(SendCampaign.java:72)

at com.*****.Run.run(Run.java:80)

at com.******.Run.main(Run.java:210)

javax.mail.MessagingException: Could not connect to SMTP host: ***.***.**.**, port: 25;

nested exception is:

java.net.ConnectException: Connection timed out: connect

at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:867)

at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:156)

at javax.mail.Service.connect(Service.java:234)

at javax.mail.Service.connect(Service.java:135)

at no.*****.send(SendCampaign.java:87)

at no.*****.send(SendCampaign.java:72)

at com.*****.mail.Run.run(Run.java:80)

at com.*******.mail.Run.main(Run.java:210)

Why do this occur sometimes after 70 mails - then just once or twice -, or after e few 100?

For, by sending for instance 1000 mails, I get everything from 1 to 20 mails that goins wrong.

Have set up a Thread to delay time between sending, and this mafde me go from a 100 wrongs (sometimes) to now 1-20.

Anyone knows if there is a way to determine a succesfull deliver, or to set the correct time between sendings?

Cincernly Paul

[2109 byte] By [olspal] at [2007-11-26 12:15:45]
# 1
Your mail server is a little weak?
quitte at 2007-7-7 14:50:52 > top of Java-index,Archived Forums,Socket Programming...
# 2
Wait a minute ?do you send all messages within a single SMTP session or do you open a new session for each single mail?
quitte at 2007-7-7 14:50:52 > top of Java-index,Archived Forums,Socket Programming...
# 3

Hey there, thanks for quick response.

For each mail I'm sending, Im creating a new session:

Properties sys_props = System.getProperties();

sys_props.put("mail.smtp.host", "***.***.**.**"));

Session session = Session.getDefaultInstance(sys_props,null);

Should i try to do it only once, or is this the best way?

Cincerly Paul

olspal at 2007-7-7 14:50:52 > top of Java-index,Archived Forums,Socket Programming...
# 4
Or if anyone else reads this, give me a few pointers:)
olspal at 2007-7-7 14:50:52 > top of Java-index,Archived Forums,Socket Programming...
# 5
I suspect email server is closing connection (could be connection timout > timeout). If you have access to email server, then check logs.
sdantam at 2007-7-7 14:50:52 > top of Java-index,Archived Forums,Socket Programming...
# 6

first of all sending same to diff emails one by one wud take lot of time

you shud create an array of Address and pass it as a parameter in "addRecipients" method

ex:- mail.addRecipients(Message.RecipientType.TO, to);

u must be usind addRecipient.

second :-

i think u need to use Session.getInstance(props,Object of your auththenticator class) in place of Session.getDefaultInstance

try this it shud work

if u want i can give u code of authenticator class also.

Vikram

VikraM at 2007-7-7 14:50:52 > top of Java-index,Archived Forums,Socket Programming...
# 7
It should be much more efficient to send the whole lot of mails within a single session, as opening the session means quite some overhead (open socket, say HELO etc.). A little delay time once in a while might give the server some air to process buffering/sending.
quitte at 2007-7-7 14:50:52 > top of Java-index,Archived Forums,Socket Programming...
# 8
Thanks for the replyI'm thinking of trying both, with the Authtenticator and just one session.Did you have any code for the Authtenticator class to be implemented? Not sure on how that works ;)Cincerly Paul
olspal at 2007-7-7 14:50:52 > top of Java-index,Archived Forums,Socket Programming...
# 9
Had a look at Session.getDefaultInstance() ?I actually don't see any performance advantage to using a single instance created by Session.getInstance()
quitte at 2007-7-7 14:50:52 > top of Java-index,Archived Forums,Socket Programming...
# 10

> It should be much more efficient to send the whole

> lot of mails within a single session, as opening the

> session means quite some overhead (open socket, say

> HELO etc.).

Should be, you say. Have you tried it? Well, I did. And I saved about 30 milliseconds per message by caching the session. Then I decided it wasn't worth the programming complexity to save those 30 milliseconds in my environment, so I didn't do it.

DrClap at 2007-7-7 14:50:52 > top of Java-index,Archived Forums,Socket Programming...
# 11

class for smtp authentication

class SMTPAuthenticator extends Authenticator {

String username;

String password;

public SMTPAuthenticator(String username,String password){

this.username=username;

this.password=password;

}

public PasswordAuthentication getPasswordAuthentication() {

return new PasswordAuthentication(username,password);

}

}

VikraM at 2007-7-7 14:50:52 > top of Java-index,Archived Forums,Socket Programming...
# 12
> Should be, you say. Have you tried it? Well, I did.Yes I did, years ago. It saved a lot when changing a mass-mailing (no spam) from individual sessions to a single one. Might depend on the network infrastructure ...
quitte at 2007-7-7 14:50:52 > top of Java-index,Archived Forums,Socket Programming...
# 13
Thanks alot, I'll get right to it; trying to short in some seconds, and to have a 100% flawless mailshipment:)
olspal at 2007-7-7 14:50:52 > top of Java-index,Archived Forums,Socket Programming...