public ActionForward executeAction() throws PureException { String host = request.getRequiredString("host", true, "host"); String user = request.getRequiredString("user", true, "user"); String password = request.getRequiredString("password", true, "password"); String systemMail = request.getRequiredString("systemMail", true, "systemMail"); String systemUser = request.getRequiredString("systemUser", true, "systemUser"); final String FROM_ADDRESS = systemMail; final String FROM_PERSON = systemUser; final String TO_ADDRESS = systemMail; final String TO_PERSON = "test"; final String SUBJECT = "srm mail test"; final String CONTENT = "SRM SYSTEM MAIL TEST"; boolean bSuccess = false; try { PureSystem.setProperty("mail.host", host); PureSystem.setProperty("mail.user", user); PureSystem.setProperty("mail.password", new String(Base64.encode(password.getBytes()))); PureSystem.setProperty("mail.system.user", systemMail); PureSystem.setProperty("mail.system.user.name", systemUser); MailSender mailSender = new MailSender(); bSuccess = mailSender.send(FROM_ADDRESS, FROM_PERSON, TO_ADDRESS, TO_PERSON, SUBJECT, CONTENT); } catch (PureException pe) { bSuccess = false; request.setAttribute("message", "发送失败!<br>" + pe.getStackTraceText()); } finally { // set pure system property to default. PureSystem.setProperty("mail.host", HOST_BACKUP); PureSystem.setProperty("mail.user", USER_BACKUP); PureSystem.setProperty("mail.password", PASSWORD_BACKUP); PureSystem.setProperty("mail.system.user", SYSTEM_MAIL_BACKUP); PureSystem.setProperty("mail.system.user.name", SYSTEM_USER_NAME_BACKUP); } if (bSuccess) { request.setAttribute("forward", "../mail/mailConfig.do"); request.setAttribute("message", "发送成功!<br>已成功发送邮件至:" + systemMail); } else { request.setAttribute("forward", "../mail/mailConfig.do"); } return mapping.findForward("success"); }
public static void main(String[] args) { try { String[] fileNames = { "F://浙江大学文本-1.txt", // "F://test.txt" }; for (int i = 0; i < fileNames.length; i++) { String sFileName = fileNames[i]; ChinesePaperTxtImport objs = null; try { objs = new ChinesePaperTxtImport(sFileName, ":"); DolphinObject obj = null; while ((obj = objs.next()) != null) ; } finally { objs.clear(); } } } catch (PureException ex) { ex.printStackTrace(); } }