No Such ProviderException: no Provider Found for pop3
843830Nov 1 2002 — edited Feb 21 2003Dear friends,
I have a peculiar problem. I have written a small program in java which connects to my mail server and fetches the mail from it and then does some operations on it. I have tested and run this program successfully in Windows Environment i.e. on Win NT/98. The program runs well . The javamail api version i have used is 1.3.
When i tried to run the program on a linux m/c the program gave an error No Such Provider Exception: No provider found for pop3. But when i changed the protocol to imap the program did not show this error and tried to execute further code. Since my mail server is of pop3 type i know it won't process any further.
My problem is why is the program not executing with pop3 protocol when the mail.jar file and activation.jar files are already present on the machine and have been specified in the classpath.
The relevant partial code for the program is listed below with the output that i get on the linux machine :
//Code for the program MailReceiver.java
public class MailReceiver
{
public MailReceiver()
{
try
{
_mailProtocol = Constants.getProperty("popprotocol");
_mailHost = Constants.getProperty("pophost");
_mailStore = null;
_mailFolder = null;
_msgsVector = null;
_userName = Constants.getProperty("popuser");
_passWord = Constants.getProperty("poppass");
_mailSession = null;
_gallery = new MediaVO();
_mms = null;
//create a properties object
Properties props = System.getProperties();
//specify the protocol settings
props.put("mail.store.protocol",_mailProtocol);
props.put("mail.mime.address.strict","false");
//get the default session
_mailSession = Session.getDefaultInstance(props,null);
//get the store
Out.println("3 "+_mailSession.toString());
mailStore = mailSession.getStore();
Out.println("4");
//connect the store
mailStore.connect(mailHost, 110,_userName,_passWord);
Out.println("5");
}
catch(javax.mail.NoSuchProviderException nspex)
{
Err.println("MailReceiver:public MailReceiver(): NoSuchProviderException: "+nspex);
}
catch(javax.mail.AuthenticationFailedException aex)
{
Err.println("MailReceiver:public MailReceiver(): AuthenticationFailedException: "+aex);
}
catch(javax.mail.MessagingException mex)
{
Err.println("MailReceiver:public MailReceiver(): MessagingException: "+mex);
}
}//end of method
public static void main(String[] args)
{
Out.println("MailReceiver:public void main():Enter");
try
{
//check if the filename is supplied or is not null
if( args.length == 0 || args[0].equals(" ") || args[0].equals("") )
{
Out.println("******Usage java MailReceiver <filename>*******");
System.exit(0);
}
//loads the file passes as argument to the static class Constants
Constants.load(args[0]);
//initailises the instance of mail receiver .
MailReceiver mr = new MailReceiver();
}
catch(java.io.IOException ioex)
{
Err.println("MailReceiver:void main():IO ex: "+ioex);
}
catch(java.lang.IllegalArgumentException illex)
{
Err.println("MailReceiver:void main():IllegalArgumentEx$
}
catch(java.lang.IllegalStateException istex)
{
Err.println("MailReceiver:void main():IllegalStateExcep$
}
}//end of method main
}//end of class
**************************
class Constants.java
public class Constants implements java.io.Serializable
{
public static Properties properties = new Properties();
//no of rows to be displayed in drum item detail screen
public static final int DRUM_ITEM_NO=10;
//max no of rows to be displayed in LLR & OTDR entry screen
public static final int OFC_MAX_ROW=20;
//this method returns the value from the properties file based on proprty name
public static String getProperty(String propertyName)
{
return properties.getProperty(propertyName);
}
//This method loads the properties file.
public static void load(String fileName) throws IOException
{
File file = new File(fileName);
properties.load(new FileInputStream(file));
System.out.println("properties load in load method of Constants."+file);
}
}//end of Constants.java
*************************
values.props file
pophost=mail.bhartitelesoft.com
popprotocol=pop3
popuser=mms
poppass=mms
*************
output with protocol set to pop3
MailReceiver:public void main():Enter
properties load in load method of Constants.values.props
MailReceiver:MailReceiver():Enter
3 javax.mail.Session@6d9f9ae
MailReceiver:public MailReceiver(): NoSuchProviderException caught: javax.mail.N
oSuchProviderException: No provider for pop3
MailReceiver:MailReceiver():Exit
output with protocol set to imap
MailReceiver:public void main():Enter
properties load in load method of Constants.values.props
MailReceiver:MailReceiver():Enter
3 javax.mail.Session@ca5f9e1
4
i.e. the program tries to connect to store accepting a protocol of imap
//end of code and output
Please i would request you to advice me as why is it behaving like this.
Thanks and regards,
Suraj B.