=============================================
import javax.mail.*;
import java.util.*;
public class MailTest
{
public static void main(String[] args)
{
Properties mailProps = new Properties();
mailProps.put("mail.transport.protocol", "smtp");
mailProps.put("mail.smtp.host", "myHost");
try {
Session session = Session.getDefaultInstance(mailProps, new LogIn());
/* also tried this - with the same result
Session session = Session.getDefaultInstance(mailProps, null); */
Store store = session.getStore();
store.connect();
Folder folder = store.getFolder("Inbox");
folder.open(Folder.READ_WRITE);
int numMsgs = folder.getMessageCount();
Message[] msgs = folder.getMessages();
for(int i = 0; i < numMsgs; ++i)
System.out.println(msgs[i].getSubject());
} catch(Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
}
}
=========================================
import javax.mail.*;
public class LogIn extends Authenticator
{
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication("username", "password");
}
}
===========================================
Here is the exception that is thrown
(NOTE: I have j2ee.jar in my class path which includes mail.jar and
activation.jar)
javax.mail.NoSuchProviderException: Invalid protocol: null
at javax.mail.Session.getProvider(Session.java:265)
at javax.mail.Session.getStore(Session.java:363)
at javax.mail.Session.getStore(Session.java:343)
at javax.mail.Session.getStore(Session.java:329)
at MailTest.main(MailTest.java:15)
Invalid protocol: null
=============================================
I thought SMTP was supposed to come with javamail, but it apparently can't
find the SMTP provider classes. Thanks for any help.
---
l8r, mike
IMO, you get the exception because you are not giving the "store"
provider, e.g.:
Properties mailProps = new Properties();
mailProps.put("mail.transport.protocol", "smtp"); // you give
transport...
mailProps.put("mail.store.protocol", "imap"); // but not store
for which there is a provider:
$ cat META-INF/javamail.default.providers
# JavaMail IMAP provider Sun Microsystems, Inc
protocol=imap; type=store; class=com.sun.mail.imap.IMAPStore;
vendor=Sun Microsystems, Inc;
# JavaMail SMTP provider Sun Microsystems, Inc
protocol=smtp; type=transport;
class=com.sun.mail.smtp.SMTPTransport; vendor=Sun Microsystems,
Inc;
# JavaMail POP3 provider Sun Microsystems, Inc
protocol=pop3; type=store; class=com.sun.mail.pop3.POP3Store;
vendor=Sun Microsystems, Inc;
(Does this make sense?) Bob L.
--
Robert Lynch Berkeley CA USA rml...@pacbell.net
javax.mail.AuthenticationFailedException
at javax.mail.Service.connect(Service.java:265)
at javax.mail.Service.connect(Service.java:135)
at javax.mail.Service.connect(Service.java:87)
at MailTest.main(MailTest.java:17)
I know for a fact the username and password I'm using are correct. The
outgoing server uses SMTP and the incoming server uses POP3. I also know
the server names I provided are correct. I'm a bit confused, as I thought
to retrieve email I would use POP3, so don't I have to specify the POP3
server somewhere?
and got the same exception.
---
l8r, mike
mailProps.put("mail.store.protocol", "pop3");
mailProps.put("mail.pop3.host", "my.pop3.server");
Also, I forgot I had commented out the line that passed an authenticator to
Session.getInstance().
---
l8r, mike
Mike N. Christoff <killallspamme...@sympatico.ca> wrote in message
news:Bbjr6.379285$f36.12...@news20.bellglobal.com...