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"); }
/** @see com.pureinfo.srm.reports.impl.STSimpleBase#getTitle() */ protected String getTitle() throws PureException { return "各" + PureSystem.getRequiredProperty("srm.org.institute-title") + "科研人员占全校的比重"; }