[英]Using JavaMail to read the mail
I am getting this error when tried to read mail using JavaMail. 尝试使用JavaMail读取邮件时出现此错误。 please let me know how to resolve this error.
请让我知道如何解决此错误。 I have added activation.jar and mail.jar into eclipse.
我已将Activation.jar和mail.jar添加到eclipse中。
DEBUG POP3: server doesn't support TOP, disabling it
javax.mail.AuthenticationFailedException: Command is not valid in this state.
at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:174)
at javax.mail.Service.connect(Service.java:291)
at javax.mail.Service.connect(Service.java:172)
at library.VerifyEmail.main(VerifyEmail.java:40)
Below is the code I am trying: 下面是我正在尝试的代码:
package library;
import java.io.IOException;
import java.util.Properties;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.NoSuchProviderException;
import javax.mail.Session;
import com.sun.mail.pop3.POP3Store;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.mail.search.SubjectTerm;
import javax.activation.*;
import java.io.*;
public class VerifyEmail {
public static void main(String[] args) throws Exception {
// SUBSTITUTE YOUR ISP's POP3 SERVER HERE!!!
String host = "myhost";
// SUBSTITUTE YOUR USERNAME AND PASSWORD TO ACCESS E-MAIL HERE!!!
String user = "myuser";
String password = "mypass";
// Get a session. Use a blank Properties object.
Session session = Session.getInstance(new Properties());
try {
// Get a Store object
Store store = session.getStore("pop3");
store.connect(host, user, password);
// Get "INBOX"
Folder fldr = store.getFolder("INBOX");
fldr.open(Folder.READ_WRITE);
int count = fldr.getMessageCount();
System.out.println(count + " total messages");
// Message numebers start at 1
for(int i = 1; i <= count; i++) {
// Get a message by its sequence number
Message m = fldr.getMessage(i);
// Get some headers
Date date = m.getSentDate();
Address [] from = m.getFrom();
String subj = m.getSubject();
String mimeType = m.getContentType();
System.out.println(date + "\t" + from[0] + "\t" +
subj + "\t" + mimeType);
}
}catch (MessagingException ioex) {
ioex.printStackTrace();
}
}
}
When you're getting the javax.mail.AuthenticationException it means that your application is unable to authenticate to the mail server. 当您获取javax.mail.AuthenticationException时,这意味着您的应用程序无法向邮件服务器进行身份验证。
One possible reason for this might be that an SSL certificate of the mail server is missing from the client keystore. 可能的原因之一是客户端密钥库中缺少邮件服务器的SSL证书。
According to microsoft : For exchange 2010, by default, the server would need the client use ssl for pop3. 根据microsoft的说法: 对于Exchange 2010,默认情况下,服务器将需要客户端将ssl用于pop3。 Without ssl the server responds with " ERR command is not valid in this state. "
如果没有ssl,服务器将以“ ERR命令在此状态下无效 ”响应。
Here's how to use javamail with ssl - Javamail and Gmail Pop3 SSL 这是将Javamail与ssl结合使用的方法-Javamail和Gmail Pop3 SSL
DEBUG POP3:服务器不支持TOP,禁用它可以通过将Java邮件jar版本更新为1.4.4来禁用此消息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.