Javamail deadlock
807588Jul 28 2009 — edited Jul 29 2009Please help me.
I have searched everywhere in this forum but I got no answer to my problem so I have decided to make a new post.
I have been getting this error for a 8days now. I am trying to send an email using Javamail API but Transport.send() and(or) Transport.sendMessage() leads to a deadlock. This is a web application. when the client submits a feedback we would like to send him an email confirmation. But then that page keep running forever. I have tried all but nothing works for me. The weird is that when I turn off tomcat the message is delivered.
Here is the code
public class MailUtil
{
public static void sendMail(String to, String from,
String subject, String body, boolean bodyIsHTML)
throws MessagingException
{
// 1 - get a mail session
//Properties props = new Properties();
Properties props = System.getProperties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", smtpserver)
props.put("mail.smtp.port", 2525);
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.connectiontimeout","20000");
props.put("mail.smtp.timeout","40000");
props.put("mail.smtp.quitwait", "false");
// create some properties and get the default Session
Session session = Session.getInstance(props, new Authenticator() {
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(authemail, authpassword);
}
});
session.setDebug(true);
// 2 - create a message
Message message = new MimeMessage(session);
java.util.Date today=new java.util.Date();
message.setSentDate(today);
message.setSubject(subject);
if (bodyIsHTML)
message.setContent(body, "text/html");
else
message.setText(body);
// 3 - address the message
message.setFrom(new InternetAddress(from));
message.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
// 4 - send the message
Transport.send(message);
}
}
this how I called it: MailUtil.sendMail(to, from, subject, body, isBodyHTML);
props.put("mail.smtp.connectiontimeout","20000");
props.put("mail.smtp.timeout","40000");
props.put("mail.smtp.quitwait", "false");
was just to see if the problem will be solved but no way
Please help me