|
|
@ -102,6 +102,7 @@ public class SnEmailGatherTask { |
|
|
|
public void parseEmail(EmailMaintainVo maintainVo){ |
|
|
|
public void parseEmail(EmailMaintainVo maintainVo){ |
|
|
|
log.info("邮箱采集内部方法开始执行--"); |
|
|
|
log.info("邮箱采集内部方法开始执行--"); |
|
|
|
log.info("解析用户"+maintainVo.getUsername()+"邮箱"); |
|
|
|
log.info("解析用户"+maintainVo.getUsername()+"邮箱"); |
|
|
|
|
|
|
|
log.info("邮箱:{}密码:{}",maintainVo.getEmailAddress(),maintainVo.getEmailPassword()); |
|
|
|
long startTime = System.currentTimeMillis(); |
|
|
|
long startTime = System.currentTimeMillis(); |
|
|
|
String password = Base64Decoder.decodeStr(maintainVo.getEmailPassword()); |
|
|
|
String password = Base64Decoder.decodeStr(maintainVo.getEmailPassword()); |
|
|
|
String emailName = maintainVo.getEmailAddress(); |
|
|
|
String emailName = maintainVo.getEmailAddress(); |
|
|
@ -369,7 +370,51 @@ public class SnEmailGatherTask { |
|
|
|
return store; |
|
|
|
return store; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
public static void main3(String[] args){ |
|
|
|
|
|
|
|
//判断是否为QQ还是163
|
|
|
|
|
|
|
|
//邮件接收协议
|
|
|
|
|
|
|
|
String emailName = "1149953701@qq.com"; |
|
|
|
|
|
|
|
String password = "pmdzleyabmlzgdhc"; |
|
|
|
|
|
|
|
String mail_protocol = "mail.store.protocol"; |
|
|
|
|
|
|
|
//邮件接收协议类型
|
|
|
|
|
|
|
|
String mail_protocol_type2 = "pop3"; |
|
|
|
|
|
|
|
String mail_protocol_type = "pop"; |
|
|
|
|
|
|
|
//邮件接收服务器端口
|
|
|
|
|
|
|
|
String mail_port = "mail.pop3.port"; |
|
|
|
|
|
|
|
//邮件接收服务器端口
|
|
|
|
|
|
|
|
String port = "110"; |
|
|
|
|
|
|
|
//邮件接收服务器地址
|
|
|
|
|
|
|
|
String mail_host = "mail.pop3.host"; |
|
|
|
|
|
|
|
String mailSuffix = emailName.split("@")[1]; |
|
|
|
|
|
|
|
//邮箱类型
|
|
|
|
|
|
|
|
String mailType = mailSuffix.split("\\.")[0]; |
|
|
|
|
|
|
|
Properties props = new Properties(); |
|
|
|
|
|
|
|
if(mailType.equalsIgnoreCase("qq")){ |
|
|
|
|
|
|
|
//qq邮箱
|
|
|
|
|
|
|
|
props.setProperty(mail_protocol, mail_protocol_type2); // 协议
|
|
|
|
|
|
|
|
props.setProperty(mail_host, mail_protocol_type+"."+mailSuffix); // pop3服务器
|
|
|
|
|
|
|
|
props.setProperty(mail_port, port); // 端口
|
|
|
|
|
|
|
|
}else { |
|
|
|
|
|
|
|
props.setProperty(mail_protocol, mail_protocol_type); // 协议
|
|
|
|
|
|
|
|
props.setProperty(mail_host, mail_protocol_type+"."+mailSuffix); // pop3服务器
|
|
|
|
|
|
|
|
props.setProperty(mail_port, port); // 端口
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Session session = Session.getInstance(props); |
|
|
|
|
|
|
|
Store store = null; |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
store = session.getStore("pop3"); |
|
|
|
|
|
|
|
store.connect(emailName, password); |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
store.close(); |
|
|
|
|
|
|
|
} catch (MessagingException ex) { |
|
|
|
|
|
|
|
throw new RuntimeException(ex); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
store = null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void main1(String[] args) { |
|
|
|
EmailMaintainVo maintainVo = new EmailMaintainVo(); |
|
|
|
EmailMaintainVo maintainVo = new EmailMaintainVo(); |
|
|
|
maintainVo.setCompanyCode("9250"); |
|
|
|
maintainVo.setCompanyCode("9250"); |
|
|
|
maintainVo.setEmailAddress("1191093413@qq.com"); |
|
|
|
maintainVo.setEmailAddress("1191093413@qq.com"); |
|
|
@ -782,91 +827,91 @@ public class SnEmailGatherTask { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
// public static void main(String[] args) {
|
|
|
|
public static void main(String[] args) { |
|
|
|
// //邮件接收协议
|
|
|
|
//邮件接收协议
|
|
|
|
// String mail_protocol = "mail.store.protocol";
|
|
|
|
String mail_protocol = "mail.store.protocol"; |
|
|
|
// //邮件接收协议类型
|
|
|
|
//邮件接收协议类型
|
|
|
|
// String mail_protocol_type2 = "pop3";
|
|
|
|
String mail_protocol_type2 = "pop3"; |
|
|
|
// String mail_protocol_type = "pop";
|
|
|
|
String mail_protocol_type = "pop"; |
|
|
|
// //邮件接收服务器端口
|
|
|
|
//邮件接收服务器端口
|
|
|
|
// String mail_port = "mail.pop3.port";
|
|
|
|
String mail_port = "mail.pop3.port"; |
|
|
|
// //邮件接收服务器端口
|
|
|
|
//邮件接收服务器端口
|
|
|
|
// String port = "110";
|
|
|
|
String port = "110"; |
|
|
|
// //邮件接收服务器地址
|
|
|
|
//邮件接收服务器地址
|
|
|
|
// String mail_host = "mail.pop3.host";
|
|
|
|
String mail_host = "mail.pop3.host"; |
|
|
|
// String emailName = "1149953701@qq.com";
|
|
|
|
String emailName = "1149953701@qq.com"; |
|
|
|
// String password = "pmdzleyabmlzgdhc";
|
|
|
|
String password = "pmdzleyabmlzgdhc"; |
|
|
|
// String mailSuffix = emailName.split("@")[1];
|
|
|
|
String mailSuffix = emailName.split("@")[1]; |
|
|
|
// //邮箱类型
|
|
|
|
//邮箱类型
|
|
|
|
// String mailType = mailSuffix.split("\\.")[0];
|
|
|
|
String mailType = mailSuffix.split("\\.")[0]; |
|
|
|
// Properties props = new Properties();
|
|
|
|
Properties props = new Properties(); |
|
|
|
// if(mailType.equalsIgnoreCase("qq")){
|
|
|
|
if(mailType.equalsIgnoreCase("qq")){ |
|
|
|
// //qq邮箱
|
|
|
|
//qq邮箱
|
|
|
|
// props.setProperty(mail_protocol, mail_protocol_type2); // 协议
|
|
|
|
props.setProperty(mail_protocol, mail_protocol_type2); // 协议
|
|
|
|
// props.setProperty(mail_host, mail_protocol_type+"."+mailSuffix); // pop3服务器
|
|
|
|
props.setProperty(mail_host, mail_protocol_type+"."+mailSuffix); // pop3服务器
|
|
|
|
// props.setProperty(mail_port, port); // 端口
|
|
|
|
props.setProperty(mail_port, port); // 端口
|
|
|
|
// }else {
|
|
|
|
}else { |
|
|
|
// props.setProperty(mail_protocol, mail_protocol_type2); // 协议
|
|
|
|
props.setProperty(mail_protocol, mail_protocol_type2); // 协议
|
|
|
|
// props.setProperty(mail_host, mail_protocol_type2+"."+mailSuffix); // pop3服务器
|
|
|
|
props.setProperty(mail_host, mail_protocol_type2+"."+mailSuffix); // pop3服务器
|
|
|
|
// props.setProperty(mail_port, port); // 端口
|
|
|
|
props.setProperty(mail_port, port); // 端口
|
|
|
|
// }
|
|
|
|
} |
|
|
|
// Session session = Session.getInstance(props);
|
|
|
|
Session session = Session.getInstance(props); |
|
|
|
// Store store = null;
|
|
|
|
Store store = null; |
|
|
|
// try {
|
|
|
|
try { |
|
|
|
// store = session.getStore("pop3");
|
|
|
|
store = session.getStore("pop3"); |
|
|
|
// store.connect(emailName, password);
|
|
|
|
store.connect(emailName, password); |
|
|
|
// //连接邮箱服务器
|
|
|
|
//连接邮箱服务器
|
|
|
|
// //获取当前时间
|
|
|
|
//获取当前时间
|
|
|
|
// Date currentTime = new Date();
|
|
|
|
Date currentTime = new Date(); |
|
|
|
// // 获得收件箱 pop3协议只有一个有效的文件夹就是INBOX
|
|
|
|
// 获得收件箱 pop3协议只有一个有效的文件夹就是INBOX
|
|
|
|
// Folder folder = store.getFolder("INBOX");
|
|
|
|
Folder folder = store.getFolder("INBOX"); |
|
|
|
// //获取邮件列表
|
|
|
|
//获取邮件列表
|
|
|
|
// folder.open(Folder.READ_WRITE);
|
|
|
|
folder.open(Folder.READ_WRITE); |
|
|
|
// // 由于POP3协议无法获知邮件的状态,所以getUnreadMessageCount得到的是收件箱的邮件总数
|
|
|
|
// 由于POP3协议无法获知邮件的状态,所以getUnreadMessageCount得到的是收件箱的邮件总数
|
|
|
|
// System.out.println("未读邮件数: " + folder.getUnreadMessageCount());
|
|
|
|
System.out.println("未读邮件数: " + folder.getUnreadMessageCount()); |
|
|
|
// // 由于POP3协议无法获知邮件的状态,所以下面得到的结果始终都是为0
|
|
|
|
// 由于POP3协议无法获知邮件的状态,所以下面得到的结果始终都是为0
|
|
|
|
// System.out.println("删除邮件数: " + folder.getDeletedMessageCount());
|
|
|
|
System.out.println("删除邮件数: " + folder.getDeletedMessageCount()); |
|
|
|
// System.out.println("新邮件: " + folder.getNewMessageCount());
|
|
|
|
System.out.println("新邮件: " + folder.getNewMessageCount()); |
|
|
|
// // 获得收件箱中的邮件总数
|
|
|
|
// 获得收件箱中的邮件总数
|
|
|
|
// System.out.println("邮件总数: " + folder.getMessageCount());
|
|
|
|
System.out.println("邮件总数: " + folder.getMessageCount()); |
|
|
|
// Message[] messages = folder.getMessages();
|
|
|
|
Message[] messages = folder.getMessages(); |
|
|
|
// for (int i = 0, count = messages.length; i < count; i++) {
|
|
|
|
for (int i = 0, count = messages.length; i < count; i++) { |
|
|
|
// MimeMessage msg = (MimeMessage) messages[i];
|
|
|
|
MimeMessage msg = (MimeMessage) messages[i]; |
|
|
|
// System.out.println("------------------解析第" + msg.getMessageNumber() + "封邮件-------------------- ");
|
|
|
|
System.out.println("------------------解析第" + msg.getMessageNumber() + "封邮件-------------------- "); |
|
|
|
// System.out.println("主题: " + EmailParseUtils.getSubject(msg));
|
|
|
|
System.out.println("主题: " + EmailParseUtils.getSubject(msg)); |
|
|
|
// System.out.println("发件人: " + EmailParseUtils.getFrom(msg));
|
|
|
|
System.out.println("发件人: " + EmailParseUtils.getFrom(msg)); |
|
|
|
// System.out.println("收件人:" + EmailParseUtils.getReceiveAddress(msg, null));
|
|
|
|
System.out.println("收件人:" + EmailParseUtils.getReceiveAddress(msg, null)); |
|
|
|
// System.out.println("发送时间:" + EmailParseUtils.getSentDate(msg, null));
|
|
|
|
System.out.println("发送时间:" + EmailParseUtils.getSentDate(msg, null)); |
|
|
|
// System.out.println("是否已读:" + EmailParseUtils.isSeen(msg));
|
|
|
|
System.out.println("是否已读:" + EmailParseUtils.isSeen(msg)); |
|
|
|
// System.out.println("邮件优先级:" + EmailParseUtils.getPriority(msg));
|
|
|
|
System.out.println("邮件优先级:" + EmailParseUtils.getPriority(msg)); |
|
|
|
// System.out.println("是否需要回执:" + EmailParseUtils.isReplySign(msg));
|
|
|
|
System.out.println("是否需要回执:" + EmailParseUtils.isReplySign(msg)); |
|
|
|
// System.out.println("邮件大小:" + msg.getSize() * 1024 + "kb");
|
|
|
|
System.out.println("邮件大小:" + msg.getSize() * 1024 + "kb"); |
|
|
|
// boolean isContainerAttachment = EmailParseUtils.isContainAttachment(msg);
|
|
|
|
boolean isContainerAttachment = EmailParseUtils.isContainAttachment(msg); |
|
|
|
// POP3Folder inbox = (POP3Folder) folder;
|
|
|
|
POP3Folder inbox = (POP3Folder) folder; |
|
|
|
// String uid = inbox.getUID(msg);
|
|
|
|
String uid = inbox.getUID(msg); |
|
|
|
// System.out.println("uid: ------------------" + uid);
|
|
|
|
System.out.println("uid: ------------------" + uid); |
|
|
|
// Flags flags = msg.getFlags();
|
|
|
|
Flags flags = msg.getFlags(); |
|
|
|
// if (!flags.contains(Flags.Flag.SEEN)) {
|
|
|
|
if (!flags.contains(Flags.Flag.SEEN)) { |
|
|
|
// //设置为已读
|
|
|
|
//设置为已读
|
|
|
|
// msg.setFlag(Flags.Flag.SEEN, true);
|
|
|
|
msg.setFlag(Flags.Flag.SEEN, true); |
|
|
|
// }
|
|
|
|
} |
|
|
|
// System.out.println("");
|
|
|
|
System.out.println(""); |
|
|
|
// }
|
|
|
|
} |
|
|
|
// System.out.println("");
|
|
|
|
System.out.println(""); |
|
|
|
// Date endTime = new Date();
|
|
|
|
Date endTime = new Date(); |
|
|
|
// //计算耗时时间
|
|
|
|
//计算耗时时间
|
|
|
|
//// double elapsedTime = CalendarUtil.arithDateTime(endTime, currentTime);
|
|
|
|
// double elapsedTime = CalendarUtil.arithDateTime(endTime, currentTime);
|
|
|
|
// // 释放资源
|
|
|
|
// 释放资源
|
|
|
|
// folder.close(false); // false为不更新邮件,true为更新,一般在删除邮件后使用
|
|
|
|
folder.close(false); // false为不更新邮件,true为更新,一般在删除邮件后使用
|
|
|
|
// store.close();
|
|
|
|
store.close(); |
|
|
|
// } catch (NoSuchProviderException e) {
|
|
|
|
} catch (NoSuchProviderException e) { |
|
|
|
// throw new RuntimeException(e);
|
|
|
|
throw new RuntimeException(e); |
|
|
|
// } catch (MessagingException e) {
|
|
|
|
} catch (MessagingException e) { |
|
|
|
// throw new RuntimeException(e);
|
|
|
|
throw new RuntimeException(e); |
|
|
|
// } catch (UnsupportedEncodingException e) {
|
|
|
|
} catch (UnsupportedEncodingException e) { |
|
|
|
// throw new RuntimeException(e);
|
|
|
|
throw new RuntimeException(e); |
|
|
|
// } catch (IOException e) {
|
|
|
|
} catch (IOException e) { |
|
|
|
// throw new RuntimeException(e);
|
|
|
|
throw new RuntimeException(e); |
|
|
|
// }
|
|
|
|
} |
|
|
|
// }
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|