List of usage examples for org.springframework.mail.javamail MimeMessageHelper setSubject
public void setSubject(String subject) throws MessagingException
From source file:mx.edu.um.mateo.rh.web.ClaveEmpleadoController.java
private void enviaCorreo(String tipo, List<ClaveEmpleado> claveEmpleados, HttpServletRequest request) throws JRException, MessagingException { log.debug("Enviando correo {}", tipo); byte[] archivo = null; String tipoContenido = null;//from www.ja v a 2 s. co m switch (tipo) { case "PDF": archivo = generaPdf(claveEmpleados); tipoContenido = "application/pdf"; break; case "CSV": archivo = generaCsv(claveEmpleados); tipoContenido = "text/csv"; break; case "XLS": archivo = generaXls(claveEmpleados); tipoContenido = "application/vnd.ms-excel"; } MimeMessage message = mailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(message, true); helper.setTo(ambiente.obtieneUsuario().getUsername()); String titulo = messageSource.getMessage("claveEmpleado.lista.label", null, request.getLocale()); helper.setSubject(messageSource.getMessage("envia.correo.titulo.message", new String[] { titulo }, request.getLocale())); helper.setText(messageSource.getMessage("envia.correo.contenido.message", new String[] { titulo }, request.getLocale()), true); helper.addAttachment(titulo + "." + tipo, new ByteArrayDataSource(archivo, tipoContenido)); mailSender.send(message); }
From source file:business.services.MailService.java
@Transactional public void notifyScientificCouncil(@NotNull RequestRepresentation request) { log.info("Notify scientic council for request " + request.getProcessInstanceId() + "."); List<User> members = userService.findScientificCouncilMembers(); for (User member : members) { log.info("Sending notification to user " + member.getUsername()); try {//w ww . java 2 s . co m MimeMessageHelper message = new MimeMessageHelper(mailSender.createMimeMessage()); message.setTo(member.getContactData().getEmail()); message.setFrom(getFrom(), fromName); message.setReplyTo(replyAddress, replyName); message.setSubject(String.format("Nieuwe PALGA-aanvraag aan u voorgelegd, aanvraagnummer: %s", request.getRequestNumber())); String requestLink = getLink("/#/request/view/" + request.getProcessInstanceId()); message.setText(String.format(scientificCouncilNotificationTemplate, requestLink)); mailSender.send(message.getMimeMessage()); } catch (MessagingException e) { log.error(e.getMessage()); throw new EmailError("Email error: " + e.getMessage()); } catch (UnsupportedEncodingException e) { log.error(e.getMessage()); throw new EmailError("Email error: " + e.getMessage()); } } }
From source file:com.campodejazayeri.wedding.AdminController.java
@RequestMapping("/testmail") @ResponseBody//from w ww. j av a 2 s . c o m public String testMail() throws Exception { MimeMessage message = mailSender.createMimeMessage(); //SimpleMailMessage msg = new SimpleMailMessage(); MimeMessageHelper msg = new MimeMessageHelper(message, "UTF-8"); msg.setFrom("Darius and Monica <campodejazayeri@gmail.com>"); msg.setTo("djazayeri@gmail.com"); msg.setSubject("Testing wedding mail"); msg.setText("Monica Campo Patio sabe escribir con ."); mailSender.send(message); return "Sent!"; }
From source file:business.services.MailService.java
public void notifyHubuser(User hubUser, List<LabRequestRepresentation> labRequests) { if (!hubUser.isHubUser()) { log.warn("The user is no hub user: " + hubUser.getUsername()); return;//from w w w. j a v a 2 s. co m } List<String> codes = new ArrayList<>(); List<String> snippets = new ArrayList<>(); for (LabRequestRepresentation labRequest : labRequests) { codes.add(labRequest.getLabRequestCode()); String link = getLink("/#/lab-request/view/" + labRequest.getId()); String snippet = String.format(hubUserNotificationLabSnippet, link, // %1 labRequest.getLabRequestCode(), // %2 labRequest.getRequest().getTitle(), // %3 labRequest.getLab().getNumber(), // %4 labRequest.getLab().getName(), // %5 labRequest.getRequesterName(), // %6 labRequest.getRequest().getPathologistName() == null ? "" : labRequest.getRequest().getPathologistName(), // %7 labRequest.getRequesterLab().getNumber(), // %8 labRequest.getRequesterLab().getName() // %9 ); snippets.add(snippet); } String labRequestCodes = String.join(", ", codes); String labRequestSnippets = String.join("\n", snippets); log.info("Notify hub user " + hubUser.getUsername() + " for lab requests " + labRequestCodes + "."); if (hubUser.getContactData() == null || hubUser.getContactData().getEmail() == null || hubUser.getContactData().getEmail().trim().isEmpty()) { log.warn("No email address set for hub user " + hubUser.getUsername()); return; } log.info("Sending notification to " + hubUser.getContactData().getEmail()); try { MimeMessageHelper message = new MimeMessageHelper(mailSender.createMimeMessage()); message.setTo(hubUser.getContactData().getEmail()); message.setFrom(getFrom(), fromName); message.setReplyTo(replyAddress, replyName); message.setSubject( String.format("PALGA-verzoek aan laboratoria, aanvraagnummers: %s", labRequestCodes)); String body = String.format(hubUserNotificationTemplate, labRequestSnippets /* %1 */); message.setText(body); mailSender.send(message.getMimeMessage()); } catch (MessagingException e) { log.error(e.getMessage()); throw new EmailError("Email error: " + e.getMessage()); } catch (UnsupportedEncodingException e) { log.error(e.getMessage()); throw new EmailError("Email error: " + e.getMessage()); } }
From source file:com.jaspersoft.jasperserver.api.engine.scheduling.quartz.ReportExecutionJobMailNotificationImpl.java
public void sendMailNotification(ReportExecutionJob job, ReportJob jobDetails, List reportOutputs) throws JobExecutionException { ReportJobMailNotification mailNotification = jobDetails.getMailNotification(); if (mailNotification != null) { try {//w ww . j a v a 2s.c o m // skip mail notification when job fails if (mailNotification.isSkipNotificationWhenJobFails() && (!job.exceptions.isEmpty())) { return; } JavaMailSender mailSender = job.getMailSender(); String fromAddress = job.getFromAddress(); MimeMessage message = mailSender.createMimeMessage(); MimeMessageHelper messageHelper = new MimeMessageHelper(message, true, job.getCharacterEncoding()); messageHelper.setFrom(fromAddress); messageHelper.setSubject(mailNotification.getSubject()); StringBuffer messageText = new StringBuffer(); addMailRecipients(mailNotification, messageHelper); boolean isEmailBodyOccupied = false; if (reportOutputs != null && !reportOutputs.isEmpty()) { byte resultSendType = jobDetails.getMailNotification().getResultSendType(); if ((resultSendType == ReportJobMailNotification.RESULT_SEND_EMBED) || (resultSendType == ReportJobMailNotification.RESULT_SEND_EMBED_ZIP_ALL_OTHERS)) { List attachmentReportList = new ArrayList(); for (Iterator it = reportOutputs.iterator(); it.hasNext();) { ReportOutput output = (ReportOutput) it.next(); if ((!isEmailBodyOccupied) && output.getFileType().equals(ContentResource.TYPE_HTML) && (job.exceptions.isEmpty())) { // only embed html output embedOutput(messageHelper, output); isEmailBodyOccupied = true; } else if (resultSendType == ReportJobMailNotification.RESULT_SEND_EMBED) { // save the rest of the output as attachments attachOutput(job, messageHelper, output, (resultSendType == ReportJobMailNotification.RESULT_SEND_ATTACHMENT)); } else { // RESULT_SEND_EMBED_ZIP_ALL_OTHERS attachmentReportList.add(output); } } if (attachmentReportList.size() > 0) { // put the rest of attachments in 1 zip file attachOutputs(job, messageHelper, attachmentReportList); } } else if (resultSendType == ReportJobMailNotification.RESULT_SEND_ATTACHMENT || resultSendType == ReportJobMailNotification.RESULT_SEND_ATTACHMENT_NOZIP) { for (Iterator it = reportOutputs.iterator(); it.hasNext();) { ReportOutput output = (ReportOutput) it.next(); attachOutput(job, messageHelper, output, (resultSendType == ReportJobMailNotification.RESULT_SEND_ATTACHMENT)); } } else if (resultSendType == ReportJobMailNotification.RESULT_SEND_ATTACHMENT_ZIP_ALL) { // put all the attachments in 1 zip file attachOutputs(job, messageHelper, reportOutputs); } else { appendRepositoryLinks(job, messageText, reportOutputs); } } if (mailNotification.isIncludingStackTraceWhenJobFails()) { if (!job.exceptions.isEmpty()) { for (Iterator it = job.exceptions.iterator(); it.hasNext();) { ExceptionInfo exception = (ExceptionInfo) it.next(); messageText.append("\n"); messageText.append(exception.getMessage()); attachException(messageHelper, exception); } } } String text = mailNotification.getMessageText(); if (!job.exceptions.isEmpty()) { if (mailNotification.getMessageTextWhenJobFails() != null) text = mailNotification.getMessageTextWhenJobFails(); else text = job.getMessage("report.scheduling.job.default.mail.notification.message.on.fail", null); } if (!isEmailBodyOccupied) messageHelper.setText(text + "\n" + messageText.toString()); mailSender.send(message); } catch (MessagingException e) { log.error("Error while sending report job result mail", e); throw new JSExceptionWrapper(e); } } }
From source file:business.services.MailService.java
public void sendActivationEmail(@NotNull ActivationLink link) { // Send email to user try {/*from ww w . j a v a2s . c o m*/ MimeMessageHelper message = new MimeMessageHelper(mailSender.createMimeMessage()); String recipient = link.getUser().getUsername(); message.setTo(recipient); message.setFrom(getFrom(), fromName); message.setReplyTo(replyAddress, replyName); message.setSubject("PALGA-account activeren / Activate PALGA account"); String activationLink = getLink("/#/activate/" + link.getToken()); message.setText(String.format(activationEmailTemplate, activationLink)); mailSender.send(message.getMimeMessage()); log.info("Activation link token generated for " + recipient + ": " + link.getToken()); } catch (MessagingException e) { log.error(e.getMessage()); throw new EmailError("Email error: " + e.getMessage()); } catch (UnsupportedEncodingException e) { log.error(e.getMessage()); throw new EmailError("Email error: " + e.getMessage()); } }
From source file:mx.edu.um.mateo.rh.web.EstudiosEmpleadoController.java
private void enviaCorreo(String tipo, List<EstudiosEmpleado> estudiosEmpleados, HttpServletRequest request) throws JRException, MessagingException { log.debug("Enviando correo {}", tipo); byte[] archivo = null; String tipoContenido = null;// w w w. java 2 s .co m switch (tipo) { case "PDF": archivo = generaPdf(estudiosEmpleados); tipoContenido = "application/pdf"; break; case "CSV": archivo = generaCsv(estudiosEmpleados); tipoContenido = "text/csv"; break; case "XLS": archivo = generaXls(estudiosEmpleados); tipoContenido = "application/vnd.ms-excel"; } MimeMessage message = mailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(message, true); helper.setTo(ambiente.obtieneUsuario().getUsername()); String titulo = messageSource.getMessage("estudiosEmpleado.lista.label", null, request.getLocale()); helper.setSubject(messageSource.getMessage("envia.correo.titulo.message", new String[] { titulo }, request.getLocale())); helper.setText(messageSource.getMessage("envia.correo.contenido.message", new String[] { titulo }, request.getLocale()), true); helper.addAttachment(titulo + "." + tipo, new ByteArrayDataSource(archivo, tipoContenido)); mailSender.send(message); }
From source file:edu.unc.lib.dl.services.MailNotifier.java
public void sendIngestSuccessNotice(IngestProperties props, int ingestedCount) { String html = null, text = null; boolean logEmail = true; MimeMessage mimeMessage = null;/*from ww w. j av a2 s . c o m*/ try { Template htmlTemplate = this.freemarkerConfiguration.getTemplate("IngestSuccessHtml.ftl", Locale.getDefault(), "utf-8"); Template textTemplate = this.freemarkerConfiguration.getTemplate("IngestSuccessText.ftl", Locale.getDefault(), "utf-8"); // put data into the model HashMap<String, Object> model = new HashMap<String, Object>(); model.put("numberOfObjects", new Integer(ingestedCount)); model.put("irBaseUrl", this.irBaseUrl); List tops = new ArrayList(); for (ContainerPlacement p : props.getContainerPlacements().values()) { HashMap om = new HashMap(); om.put("pid", p.pid.getPid()); om.put("label", p.label); tops.add(om); } model.put("tops", tops); StringWriter sw = new StringWriter(); htmlTemplate.process(model, sw); html = sw.toString(); sw = new StringWriter(); textTemplate.process(model, sw); text = sw.toString(); } catch (IOException e1) { throw new Error("Unable to load email template for Ingest Success", e1); } catch (TemplateException e) { throw new Error("There was a problem loading FreeMarker templates for email notification", e); } try { if (log.isDebugEnabled() && this.mailSender instanceof JavaMailSenderImpl) { ((JavaMailSenderImpl) this.mailSender).getSession().setDebug(true); } mimeMessage = mailSender.createMimeMessage(); MimeMessageHelper message = new MimeMessageHelper(mimeMessage, MimeMessageHelper.MULTIPART_MODE_MIXED); for (String addy : props.getEmailRecipients()) { message.addTo(addy); } message.setSubject("CDR ingest complete"); message.setFrom(this.getRepositoryFromAddress()); message.setText(text, html); // attach Events XML // Document events = new Document(aip.getEventLogger().getAllEvents()); // message.addAttachment("events.xml", new JDOMStreamSource(events)); this.mailSender.send(mimeMessage); logEmail = false; } catch (MessagingException e) { log.error("Unable to send ingest success email.", e); } catch (RuntimeException e) { log.error(e); } finally { if (mimeMessage != null && logEmail) { try { mimeMessage.writeTo(System.out); } catch (Exception e) { log.error("Could not log email message after error.", e); } } } }
From source file:com.devnexus.ting.core.service.integration.GenericEmailToMimeMessageTransformer.java
@Transformer public MimeMessage prepareMailToSpeaker(GenericEmail email) { final MimeMessage mimeMessage = this.mailSender.createMimeMessage(); MimeMessageHelper messageHelper; try {/*www . j av a 2s . c o m*/ messageHelper = new MimeMessageHelper(mimeMessage, true); messageHelper.setText(email.getText(), email.getHtml()); messageHelper.setFrom(email.getFrom()); for (String emailToAddress : email.getTo()) { messageHelper.addTo(emailToAddress); } if (!email.getCc().isEmpty()) { for (String emailCcAddress : email.getCc()) { messageHelper.addCc(emailCcAddress); } } messageHelper.setSubject(email.getSubject()); } catch (MessagingException e) { throw new IllegalStateException("Error creating mail message for email: " + email, e); } return messageHelper.getMimeMessage(); }
From source file:business.services.MailService.java
public void sendPasswordRecoveryToken(NewPasswordRequest npr) { try {/* w w w . j a v a 2s . com*/ MimeMessageHelper message = new MimeMessageHelper(mailSender.createMimeMessage()); String recipient = npr.getUser().getContactData().getEmail(); message.setTo(recipient); message.setFrom(getFrom(), fromName); message.setReplyTo(replyAddress, replyName); message.setSubject(passwordRecoverySubject); String passwordRecoveryLink = getLink("/#/login/reset-password/" + npr.getToken()); message.setText(String.format(passwordRecoveryTemplate, passwordRecoveryLink)); log.info("Sending password recovery token to " + recipient + "."); mailSender.send(message.getMimeMessage()); } catch (MessagingException e) { log.error(e.getMessage()); throw new EmailError("Email error: " + e.getMessage()); } catch (UnsupportedEncodingException e) { log.error(e.getMessage()); throw new EmailError("Email error: " + e.getMessage()); } }