|
@@ -10,6 +10,10 @@ import javax.activation.DataHandler;
|
|
|
import javax.activation.FileDataSource;
|
|
|
import javax.mail.*;
|
|
|
import javax.mail.internet.*;
|
|
|
+import javax.mail.search.AndTerm;
|
|
|
+import javax.mail.search.FromTerm;
|
|
|
+import javax.mail.search.SearchTerm;
|
|
|
+import javax.mail.search.SentDateTerm;
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
@@ -20,7 +24,7 @@ import java.util.Properties;
|
|
|
@Slf4j
|
|
|
public class EmailUtilsNew {
|
|
|
|
|
|
- private static final String ALIDM_SMTP_HOST = "smtpdm.aliyun.com";
|
|
|
+ private static final String ALIDM_SMTP_HOST = "smtp.exmail.qq.com";
|
|
|
private static final int ALIDM_SMTP_PORT = 80;// 或80
|
|
|
|
|
|
|
|
@@ -139,7 +143,7 @@ public class EmailUtilsNew {
|
|
|
|
|
|
Properties props = new Properties();
|
|
|
props.setProperty("mail.store.protocol", "imap");
|
|
|
- props.setProperty("mail.imap.host", "imap.qq.com");
|
|
|
+ props.setProperty("mail.imap.host", ALIDM_SMTP_HOST);
|
|
|
props.setProperty("mail.imap.port", "993");
|
|
|
props.setProperty("mail.imap.auth.login.disable", "true");
|
|
|
props.setProperty("mail.imap.ssl.enable", "true");
|
|
@@ -150,7 +154,7 @@ public class EmailUtilsNew {
|
|
|
IAM.put("name","李斌");
|
|
|
IAM.put("version","1.0.0");
|
|
|
IAM.put("vendor","myclient");
|
|
|
- IAM.put("support-email","15920909481@163.com");
|
|
|
+ IAM.put("support-email","17607626121@163.com");
|
|
|
|
|
|
Session session = Session.getInstance(props, new Authenticator() {
|
|
|
public PasswordAuthentication getPasswordAuthentication() {
|
|
@@ -158,17 +162,24 @@ public class EmailUtilsNew {
|
|
|
return new PasswordAuthentication(user, password);
|
|
|
}
|
|
|
});
|
|
|
- IMAPStore store = (IMAPStore)session.getStore("imap");
|
|
|
+ Store store = (IMAPStore)session.getStore("imap");
|
|
|
// imap.qq.com
|
|
|
- store.connect("imap.163.com", user, password);
|
|
|
- store.id(IAM);
|
|
|
+ store.connect(ALIDM_SMTP_HOST, user, password);
|
|
|
+
|
|
|
+
|
|
|
// 获得邮箱内的邮件夹Folder对象,以"只读"打开
|
|
|
- Folder folder = store.getFolder("INBOX");
|
|
|
+ Folder inbox = store.getFolder("INBOX");
|
|
|
+
|
|
|
//folder.open(Folder.READ_ONLY);
|
|
|
- folder.open(Folder.READ_WRITE);
|
|
|
+ inbox.open(Folder.READ_WRITE);
|
|
|
+
|
|
|
+ SearchTerm sinceTerm = new SentDateTerm(SentDateTerm.GE, DateUtil.beginOfDay(new Date()));
|
|
|
+ SearchTerm sentDateTerm = new SentDateTerm(SentDateTerm.GE, DateUtil.beginOfDay(new Date()));
|
|
|
+
|
|
|
+ SearchTerm searchTerm = new AndTerm(sinceTerm,sentDateTerm);
|
|
|
|
|
|
// 获得邮件夹Folder内的所有邮件Message对象
|
|
|
- Message [] messages = folder.getMessages();
|
|
|
+ Message [] messages = inbox.search(searchTerm);
|
|
|
|
|
|
int mailCounts = messages.length;
|
|
|
for(int i = 0; i < mailCounts; i++) {
|
|
@@ -179,7 +190,7 @@ public class EmailUtilsNew {
|
|
|
//今天接收的邮件
|
|
|
if(receivedDate.getTime() > DateUtil.beginOfDay(new Date()).getTime() && from.indexOf(receEmail) > -1){
|
|
|
messages[i].setFlag(Flags.Flag.SEEN, true);
|
|
|
- folder.close(false);
|
|
|
+ inbox.close(false);
|
|
|
store.close();
|
|
|
return true;
|
|
|
}
|
|
@@ -195,7 +206,7 @@ public class EmailUtilsNew {
|
|
|
// messages[i].writeTo(System.out);
|
|
|
// }
|
|
|
}
|
|
|
- folder.close(false);
|
|
|
+ inbox.close(false);
|
|
|
store.close();
|
|
|
return false;
|
|
|
}
|