public String getEmailAddresses(String string) { String hql = "from EmailUserSetting emailset where emailset.user = '******'"; List<EmailUserSetting> emailSettings = this.emailUserSettingDao.findEmailUserSettings(hql); String jsonString = "{emailSelect:["; for (int i = 0; i < emailSettings.size(); i++) { EmailUserSetting emailSetting = emailSettings.get(i); String settingString = "{"; settingString += "\"emailId\":\"" + emailSetting.getId() + "\","; settingString += "\"emailAddress\":\"" + emailSetting.getEmailAddress() + "\""; settingString += "},"; jsonString += settingString; } jsonString = jsonString.substring(0, jsonString.length() - 1); jsonString += "]}"; System.out.println(jsonString); return jsonString; }
public MimeMessage getMessage(String emailSetId, String mailId) { String hql = "from EmailUserSetting emailset where emailset.id = '" + Integer.valueOf(emailSetId) + "'"; EmailUserSetting emailUserSetting = emailUserSettingDao.findEmailUserSetting(hql); Properties props = new Properties(); Session session = Session.getDefaultInstance(props, null); Store store = null; Message message[] = null; try { store = session.getStore("pop3"); store.connect( emailUserSetting.getPopService(), emailUserSetting.getEmailAddress(), emailUserSetting.getPassword()); Folder folder = store.getFolder("INBOX"); folder.open(Folder.READ_ONLY); message = folder.getMessages(); } catch (NoSuchProviderException e) { e.printStackTrace(); } catch (MessagingException e) { e.printStackTrace(); } // System.out.println("Messages's length: "+message.length); MimeMessage pmm = null; for (int i = 0; i < message.length; i++) { pmm = (MimeMessage) message[i]; String eId = null; try { eId = pmm.getMessageID(); } catch (MessagingException e) { e.printStackTrace(); } if (eId != null && eId.equals(mailId)) { return pmm; } } return null; }
public SmtpMailSender getSmtpMailSender(String senderId) { String hql = "from EmailUserSetting emailset where emailset.emailAddress = '" + senderId + "'"; EmailUserSetting emailUserSetting = emailUserSettingDao.findEmailUserSetting(hql); // System.out.println(emailUserSetting.getStmpService()+" // "+"\"Object\"<"+emailUserSetting.getEmailAddress()+">"+" // "+emailUserSetting.getEmailAddress()+" "+emailUserSetting.getPassword()); return SmtpMailSender.createESmtpMailSender( emailUserSetting.getStmpService(), "\"" + emailUserSetting.getName() + "\"<" + emailUserSetting.getEmailAddress() + ">", emailUserSetting.getEmailAddress(), emailUserSetting.getPassword()); }
public String getMessages(String userId, String emailSetId) { String hql = "from EmailUserSetting emailset where emailset.id = '" + Integer.valueOf(emailSetId) + "'"; EmailUserSetting emailUserSetting = emailUserSettingDao.findEmailUserSetting(hql); Properties props = new Properties(); Session session = Session.getDefaultInstance(props, null); Store store = null; Message message[] = null; try { store = session.getStore("pop3"); store.connect( emailUserSetting.getPopService(), emailUserSetting.getEmailAddress(), emailUserSetting.getPassword()); Folder folder = store.getFolder("INBOX"); folder.open(Folder.READ_ONLY); message = folder.getMessages(); } catch (NoSuchProviderException e) { e.printStackTrace(); } catch (MessagingException e) { e.printStackTrace(); } System.out.println("Messages's length: " + message.length); PraseMimeMessage pmm = null; String jsonString = "{'mails':["; for (int i = 0; i < message.length; i++) { pmm = new PraseMimeMessage((MimeMessage) message[i]); try { String mailString = "{"; mailString += "'mailId' : '" + pmm.getMessageId() + "',"; mailString += "'theme':'" + pmm.getSubject() + "',"; mailString += "'sender':'" + pmm.getFrom() + "',"; pmm.setDateFormat("yy年MM月dd日 HH:mm:ss"); mailString += "'time':'" + pmm.getSentDate() + "',"; mailString += "'files':'"; if (pmm.isContainAttach((Part) message[i])) { List<String> files = pmm.getFilenames(); for (int j = 0; j < files.size(); j++) { mailString += files.get(j) + ";"; } mailString += "',"; } else { mailString += "',"; } pmm.getMailContent((Part) message[i]); String content = pmm.getBodyText(); content = content.replaceAll("\r|\n", ""); mailString += "'content':'" + content + "'"; mailString += "},"; jsonString += mailString; } catch (Exception e) { e.printStackTrace(); } } jsonString = jsonString.substring(0, jsonString.length() - 1); jsonString += "]}"; System.out.println(jsonString); return jsonString; }