T
TC
Java 1.4.2
JavaMail API 1.3.2
NetBeans 4.1
I have done quite a bit of research on this issue and cannot find the
problem. I've even checked with one of our local programmers.
I created one program that connects to our smtp server and sends an
email. This works fine. Now, I'm trying to create a program that
connects to the smtp server and reads/gets the email message subjects.
This is failing. I have tried changing the getStore("pop3") to
getStore("smtp") but this gives the error "Invalid provider". If I use
caps (SMTP), I get "No provider for SMTP".
The host I'm using is the same as what I use to send mail. I have
mail.jar and authentication.jar in my Project Compiling Sources dir.
I'm guessing it means it's in my CLASSSPATH.
The META-INF file found in the JavaMail\lib\ dir contains .jar files
for pop3 and smtp. Do I need to add my host to the smtp.jar file?
Here's my code:
*
* ReadMail.java
*
* Created on November 4, 2004, 10:20 AM
*/
/**
*
* @author jmartin
*/
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
public class ReadMail {
public static void main (String agrs[])
throws Exception {
try {
String host = "server.mydomain.com";
String userName = ""; // Has a valid username
String password = ""; // Has a valid passwd
// Create empty properties
Properties props = new Properties();
// Get session
Session session = Session.getDefaultInstance(props, null);
// Get the store
Store store = session.getStore("pop3");
store.connect(host, userName, password);
// Get folder
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
// Get directory
Message message[] = folder.getMessages();
for (int i=0, n=message.length; i<n; i++){
System.out.println(i + ": " + message.getFrom()[0]
+ "\t" + message.getSubject());
}
// Close connection
folder.close(false);
store.close();
} // try
catch (Exception e){
System.out.println("There was an error.");
e.printStackTrace();
}
} // main
}
JavaMail API 1.3.2
NetBeans 4.1
I have done quite a bit of research on this issue and cannot find the
problem. I've even checked with one of our local programmers.
I created one program that connects to our smtp server and sends an
email. This works fine. Now, I'm trying to create a program that
connects to the smtp server and reads/gets the email message subjects.
This is failing. I have tried changing the getStore("pop3") to
getStore("smtp") but this gives the error "Invalid provider". If I use
caps (SMTP), I get "No provider for SMTP".
The host I'm using is the same as what I use to send mail. I have
mail.jar and authentication.jar in my Project Compiling Sources dir.
I'm guessing it means it's in my CLASSSPATH.
The META-INF file found in the JavaMail\lib\ dir contains .jar files
for pop3 and smtp. Do I need to add my host to the smtp.jar file?
Here's my code:
*
* ReadMail.java
*
* Created on November 4, 2004, 10:20 AM
*/
/**
*
* @author jmartin
*/
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
public class ReadMail {
public static void main (String agrs[])
throws Exception {
try {
String host = "server.mydomain.com";
String userName = ""; // Has a valid username
String password = ""; // Has a valid passwd
// Create empty properties
Properties props = new Properties();
// Get session
Session session = Session.getDefaultInstance(props, null);
// Get the store
Store store = session.getStore("pop3");
store.connect(host, userName, password);
// Get folder
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
// Get directory
Message message[] = folder.getMessages();
for (int i=0, n=message.length; i<n; i++){
System.out.println(i + ": " + message.getFrom()[0]
+ "\t" + message.getSubject());
}
// Close connection
folder.close(false);
store.close();
} // try
catch (Exception e){
System.out.println("There was an error.");
e.printStackTrace();
}
} // main
}