List of usage examples for org.apache.commons.mail Email ISO_8859_1
String ISO_8859_1
To view the source code for org.apache.commons.mail Email ISO_8859_1.
Click Source Link
From source file:dk.cubing.liveresults.action.admin.ScoresheetAction.java
/** * @return/* ww w. j a v a 2s . c o m*/ */ public String exportResults() { if (competitionId != null) { Competition competitionTemplate = getCompetitionService().find(competitionId); if (competitionTemplate == null) { log.error("Could not load competition: {}", competitionId); return Action.ERROR; } setCompetition(competitionTemplate); try { // load WCA template from file InputStream is = ServletActionContext.getServletContext() .getResourceAsStream(getSpreadSheetFilename()); Workbook workBook; workBook = WorkbookFactory.create(is); is.close(); // build special registration sheet generateRegistrationSheet(workBook, getCompetition()); // build result sheets generateResultSheets(workBook, getCompetition()); // set default selected sheet workBook.setActiveSheet(workBook.getSheetIndex(SHEET_TYPE_REGISTRATION)); // email or just output to pdf? if (isSubmitResultsToWCA()) { // write workbook to temp file File temp = File.createTempFile(getCompetitionId(), ".xls"); temp.deleteOnExit(); OutputStream os = new FileOutputStream(temp); workBook.write(os); os.close(); // Create the attachment EmailAttachment attachment = new EmailAttachment(); attachment.setPath(temp.getPath()); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setName(getCompetitionId() + ".xls"); // send email MultiPartEmail email = new MultiPartEmail(); email.setCharset(Email.ISO_8859_1); email.setHostName(getText("email.smtp.server")); if (!getText("email.username").isEmpty() && !getText("email.password").isEmpty()) { email.setAuthentication(getText("email.username"), getText("email.password")); } email.setSSL("true".equals(getText("email.ssl"))); email.setSubject("Results from " + getCompetition().getName()); email.setMsg(getText("admin.export.message", new String[] { getCompetition().getName(), getCompetition().getOrganiser() })); email.setFrom(getCompetition().getOrganiserEmail(), getCompetition().getOrganiser()); email.addTo(getText("admin.export.resultsteamEmail"), getText("admin.export.resultsteam")); email.addCc(getCompetition().getOrganiserEmail(), getCompetition().getOrganiser()); email.addCc(getCompetition().getWcaDelegateEmail(), getCompetition().getWcaDelegate()); email.attach(attachment); email.send(); return Action.SUCCESS; } else { // output generated spreadsheet log.debug("Ouputting generated workbook"); out = new ByteArrayOutputStream(); workBook.write(out); out.close(); return "spreadsheet"; } } catch (InvalidFormatException e) { log.error("Spreadsheet template are using an unsupported format.", e); } catch (IOException e) { log.error("Error reading spreadsheet template.", e); } catch (EmailException e) { log.error(e.getMessage(), e); } return Action.ERROR; } else { return Action.INPUT; } }
From source file:org.ploin.pmf.impl.MailSender.java
/** * * @param email - the MultipartEmail/*w w w.j a v a2 s .c o m*/ * @param mailConfig - the mail config object * @param serverConfig - the server config object * @return SendingResult object */ private SendingResult send(MultiPartEmail email, MailConfig mailConfig, ServerConfig serverConfig) throws MailFactoryException { try { email.setCharset(Email.ISO_8859_1); setServerProperties(email, serverConfig); setMailProperties(email, mailConfig); setAttachements(email, mailConfig); // here is a bug in apache commons email ... problems with html and attachements String sendMessage = email.send(); log.debug("email.send() = " + sendMessage); SendingResult sendingResult = new SendingResult(); sendingResult.setResult(sendMessage); sendingResult.setMimeMessage(email.getMimeMessage()); return sendingResult; } catch (Exception e) { throw new MailFactoryException(e); } }