• Post Reply Bookmark Topic Watch Topic
  • New Topic

JavaMail and Network Connection Issue  RSS feed

 
Benjamin Sundarsingh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
private void sendEmail(String subject,String emailText) throws Exception
{
MimeBodyPart mbp1 = null;
MimeMultipart mp = null;
Message msg = null;
Properties props = System.getProperties();
props.put("mail.smtp.host","mymail.mycomp.com");
Session sessionVal=Session.getDefaultInstance(props, null);
msg = new MimeMessage(sessionVal);
msg.setFrom(new InternetAddress("bob@mycomp.com"));
msg.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("tom@mycomp.com", false));
msg.setSubject(subject);
mbp1 = new MimeBodyPart();
mbp1.setText(emailText);
mp = new MimeMultipart();
mp.addBodyPart(mbp1);
msg.setContent(mp);
msg.setDataHandler(new DataHandler(
new ByteArrayDataSource(emailText,
"text/html")
)
);
Transport.send(msg);
}
This is the method that I use to send mails. It works fine under normal circumstance, but I get UnknownHostException soon after I disconnect and reconnect my network cable.

I can understand the exception when network is not available but I dont understand why I get the same exception after reconnecting the network cable.

I use this program to send mails after server outage. Instead of stopping the server I disconnected my network cable but sadly even after plugging back the cable it does not work.

Looks to me the Session object 'remembers'... please advice
 
Benjamin Sundarsingh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry I forgot, I use Java 1.3.1
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!