Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Null ptr exception in javax.mail -- HELP!

843830Dec 31 2003 — edited Dec 12 2007
Here is the first thing I've tried, I've modeled it after other programs that work, but I get a null pointer exception. Any help would be greatly appreciated. The exception happens in the call to Transport.send ().

Thanks for any help
Russ


  public static void main (String argv[]) {
  try {
    Properties p=System.getProperties();
    p.put("mail.smtp.host","mail.healthtrans.com");
    Session session=Session.getDefaultInstance(p,null);
    Message message=new MimeMessage(session);
    message.setFrom(new InternetAddress
        ("rheithoff@healthtrans.com"));
    message.setRecipient(Message.RecipientType.TO,
      new InternetAddress("rheithoff@healthtrans.com"));
    message.setSubject("Java Mail Test");
    message.setSentDate(new Date());
    message.setText("Did you get this?");
    Transport.send(message);
  }
  catch(SendFailedException sfe) {
    System.out.println(sfe.getMessage());
    sfe.printStackTrace();
  }
  catch(MessagingException me) {
    me.printStackTrace();
  }
  }


Exception in thread "main" java.lang.NullPointerException
at java.net.InetAddress.cacheAddress(InetAddress.java:667)
at java.net.InetAddress.cacheAddress(InetAddress.java:652)
at java.net.InetAddress.getAddressFromNameService(InetAddress.java:1034)
at java.net.InetAddress.getLocalHost(InetAddress.java:1142)
at com.sun.mail.smtp.SMTPTransport.getLocalHost(SMTPTransport.java:95)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:200)
at javax.mail.Service.connect(Service.java:233)
at javax.mail.Service.connect(Service.java:134)
at javax.mail.Service.connect(Service.java:86)
at com.sun.mail.smtp.SMTPTransport.connect(SMTPTransport.java:104)
at javax.mail.Transport.send0(Transport.java:162)
at javax.mail.Transport.send(Transport.java:80)
at SendMail.main(SendMail.java:21)
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 9 2008
Added on Dec 31 2003
4 comments
388 views