Exception in thread "main" javax.mail.MessagingException: Failed to load IMAP envelope
at com.sun.mail.imap.IMAPMessage.loadEnvelope(IMAPMessage.java:1069)
at com.sun.mail.imap.IMAPMessage.getSubject(IMAPMessage.java:256)
at WSLTest.main(WSLTest.java:47)
主要原因是使用了smtp接受方式。应该为imap
private static FlagTerm recentTerm = new FlagTerm(new Flags(Flags.Flag.RECENT),
true);
public static String myEmailSMTPHost = "imap.qiye.163.com";
public static String myEmailAccount = "邮箱";
public static String myEmailPassword = "密码";
public static void reserveemail() throws Exception {
Properties props = new Properties();
props.setProperty("mail.store.protocol", "imap");
props.setProperty("mail.imap.host", "imap.qiye.163.com");
props.setProperty("mail.imap.port", "143");
Store store = null;
// 用来存放邮件中文件夹的,可以简单的使用javax.mail.Folder类型,
// 如果只是取未读邮件数的话Folder类型就够了
try {
Session session = Session.getInstance(props);
//如果使用pop3协议这里imap改成pop3,如果使用ssl连接这里应使用imaps
store = session.getStore("imap");
store.connect(myEmailAccount,myEmailPassword);
//System.out.println(store);
Folder folder = getInboxFolder(store, false); //取得收件箱对象
//如果需要在取得邮件数后将邮件置为已读则这里需要使用READ_WRITE,否则READ_ONLY就可以
// 获得收件箱的邮件列表
Message[] messages = folder.search(recentTerm);
for (Message message : messages) {
try{
IMAPMessage msg = (IMAPMessage) message;
System.out.println(msg.getSubject());
//InventecEmailProcessor iema=new InventecEmailProcessor();
//iema.resolvemsg(msg);
msg.setFlag(Flags.Flag.SEEN, true);
}catch(Exception e){
e.printStackTrace();
}
}
// Message messages[] = inbox.getMessages(); //获取所有邮件
//建立搜索条件FlagTerm,这里FlagTerm继承自SearchTerm,也就是说除了获取未读邮
//件的条件还有很多其他条件同样继承了SearchTerm的条件类,像根据发件人,主题搜索等,
// 还有复杂的逻辑搜索类似:
//
// SearchTerm orTerm = new OrTerm(
// new FromStringTerm(from),
// new SubjectTerm(subject)
// );
//
// 可以上网搜索SearchTerm获取更多
/*FlagTerm ft = new FlagTerm(new Flags(Flags.Flag.SEEN), false); //false代表未读,true代表已读
*//**
* Flag 类型列举如下
* Flags.Flag.ANSWERED 邮件回复标记,标识邮件是否已回复。
* Flags.Flag.DELETED 邮件删除标记,标识邮件是否需要删除。
* Flags.Flag.DRAFT 草稿邮件标记,标识邮件是否为草稿。
* Flags.Flag.FLAGGED 表示邮件是否为回收站中的邮件。
* Flags.Flag.RECENT 新邮件标记,表示邮件是否为新邮件。
* Flags.Flag.SEEN 邮件阅读标记,标识邮件是否已被阅读。
* Flags.Flag.USER 底层系统是否支持用户自定义标记,只读。
*//*
Message messages[] = inbox.search(ft); //根据设置好的条件获取message
System.out.println("邮件总共:"+messages.length+"封");
// System.out.println("11111111111111");
//遍历获取的Message数组获取信息
for (Message message : messages) {
try{
System.out.println(message.getSubject().toString());
message.setFlag(Flags.Flag.SEEN, true);
}catch(Exception e){
//e.printStackTrace();
System.out.println("读取出错!======================");
//message.setFlag(Flags.Flag.SEEN, true);
}
}
//inbox.setFlags(messages, new Flags(Flags.Flag.SEEN),true);
*/
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
if (store != null) {
store.close();
store = null;
}
} catch (MessagingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
/**
* 获取文件夹 这里是收件箱
*
* @param store
* @param readOnly
* @return
* @throws MessagingException
*/
private static IMAPFolder getInboxFolder(Store store, boolean readOnly)
throws MessagingException {
IMAPFolder folder = (IMAPFolder) store.getFolder("INBOX");
if (!folder.isOpen()) {
if (readOnly) {
folder.open(Folder.READ_ONLY);
} else {
folder.open(Folder.READ_WRITE);
}
}
return folder;
}
相关推荐
javax.mail.MessagingException: Could not connect to SMTP host: zxkaka.com, port: 25; 出现这个问题时,我在foxmail 以及 outlook都可以发送邮件的。 免得自己以后忘记,在源码里注释写的很清楚
power load-pull and envelope load-pull setups with applications to amplifier, mixer and noise measurements. In addition, the book also covers waveform engineering systems, their calibration techniques...
java error:bad envelope tag :title
包络函数的求取,希望对需要的人有所帮助。自己感觉程序还不错,已经运行过了,没有错误。
用来提取信号包络的matlab函数 觉得好的下来
智能交易 Envelope 2。
包络谱的求取程序,已经过matlab运行,没有问题。
A time-domain method to extract the envelope of an amplitude modulated signal at high speed is presented. This method, the envelope detection filter (EDF), is based on a nonlinear function of two ...
介紹基於xml形式的xcbl文件通過ibx平臺的傳輸封裝形式。
Laravel开发-log-envelope Laravel 5出错电子邮件
信号 包络线 信号 MATLAB的 M 文件 验证过的很好用
compute the envelope spectrum
python库。资源全名:envelope-1.4.tar.gz
文献:Envelope pulsed ultrasonic distance measurement system based upon amplitude modulation and phase modulation 关键词:自干涉;超声波
Hasp HL Envelope Tutorial
A PIECEWISE ENVELOPE APPROACH TO H∞ CONTROL OF NONLINEAR SYSTEMS
a spectral envelope estimator for high-quality speech synthesis Masanori Morise
商战-信封文件生成工具
Rayleigh Fading Envelope.zip
金额固定/随机金额