tsgrp / OpenContent

TSG's Web Services for ECM Repositories
8 stars 4 forks source link

EmailImpl Infinite Timeout #40

Open benallenallen opened 10 years ago

benallenallen commented 10 years ago

Problem can occur where the thread used to kick off an email never completes and just spins infinitely.

The reason is that Transport.send with SMTP has two infinite timeouts which can result in your process just hanging.

If we update this to throw an exception when an email fails to send, we need to be sure that all calling code can properly handle an exception being thrown when one previously was not being thrown.

Most efficient place to fix this would be to set some sensible defaults in the tsgrp.jar in TsgEmailMessage.java and to throw a real exception if the timeout occurs.

From Oracle documentation: mail.smtp.connectiontimeout int Socket connection timeout value in milliseconds. Default is infinite timeout. mail.smtp.timeout int Socket I/O timeout value in milliseconds. Default is infinite timeout.

To not "hang" forever, you can set these explicitly. Assuming that you are using smtp, add the following where t1 and t2 are your timeouts in ms:

    props.put("mail.smtp.connectiontimeout", "t1");
    props.put("mail.smtp.timeout", "t2");

Note that if you're using the "smtps" protocol to access SMTP over SSL, all the properties would be named "mail.smtps.*".