This discussion is archived
4 Replies Latest reply: Dec 21, 2010 10:29 AM by forumKid2 RSS

javax.mail.NoSuchProviderException: Invalid protocol :null

621312 Newbie
Currently Being Moderated
Hi,
I know this is discussed a lot of times in the forum. my case is a bit different, any sort of help is appreciated.

I use activation.jar and mail.jar for sending emails for my application. I am not getting emails in certain cases. The same code is used for sending emails for all the application interfaces. Only in certain cases, i get the following error,

javax.mail.NoSuchProviderException: Invalid protocol :null

This is the code i use,

Properties sessionConfig = new Properties();
          sessionConfig.put("mail.transport.protocol",
          "smtp");
System.out.println("smtphost "+smtpHost);
          sessionConfig.put("mail.smtp.host",
                    smtpHost);
          sessionConfig.put("from",
          "from");
          sessionConfig.put("body",
     "No body for this message.");
          sessionConfig.put("subject",
          "No subject for this message.");
          _session = Session.getDefaultInstance(sessionConfig, null);
transport = _session.getTransport();
               transport.connect();
               transport.addConnectionListener(new ConnectionEventListener());
               transport.addTransportListener(new TransportEventListener());
               MimeMessage transportMessage=getMessage(message);
               transport.sendMessage(transportMessage,
                         transportMessage.getAllRecipients());

this happens only in certain cases. And the protocol is set properly. the classpath has only these two jars.

regards,
Aravind

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points