public static void DuReceiveEmail(String pop3Host,String storeType, String user, String password){ Properties props = new Properties(); props.put("mail.pop3.host", pop3Host); props.put("mail.pop3.port", "110"); props.put("mail.pop3.starttls.enable", "false"); props.put("mail.store.protocol", "pop3"); Session session = Session.getInstance(props); try { Store mailStore = session.getStore(storeType); mailStore.connect(pop3Host, user, password); Folder folder = mailStore.getFolder("INBOX"); folder.open(Folder.READ_ONLY); Message[] emailMessages = folder.getMessages(); System.out.println("Total Message - " + emailMessages.length); //Iterate the messages for (int i = 0; i < emailMessages.length; i++) { Message message = emailMessages[i]; Address[] toAddress = message.getRecipients(Message.RecipientType.TO); System.out.println(); System.out.println("Email " + (i+1) + "-"); System.out.println("Subject - " + message.getSubject()); System.out.println("From - " + message.getFrom()[0]); System.out.println("To - "); for(int j = 0; j < toAddress.length; j++){ System.out.println(toAddress[j].toString()); } System.out.println("Text - " + message.getContent().toString()); } folder.close(false); mailStore.close(); } catch (Exception e) { e.printStackTrace(); System.err.println("Error in receiving email."); } } public static void receiveEmail(String pop3Host, String storeType, String user, String password) { try { //1) get the session object Properties properties = new Properties(); properties.put("mail.pop3.host", pop3Host); Session emailSession = Session.getDefaultInstance(properties); //2) create the POP3 store object and connect with the pop server POP3Store emailStore = (POP3Store) emailSession.getStore(storeType); emailStore.connect(user, password); //3) create the folder object and open it Folder emailFolder = emailStore.getFolder("INBOX"); emailFolder.open(Folder.READ_ONLY); //获取邮箱基本信息 // Map
java:javamail1.6.2CreateReceiveEmailusingjdk19
时间:2023-08-01
下一篇:区间合并算法
相关推荐