List of usage examples for org.springframework.mail.javamail MimeMessageHelper MimeMessageHelper
public MimeMessageHelper(MimeMessage mimeMessage, int multipartMode) throws MessagingException
From source file:mx.edu.um.mateo.rh.web.JefeRHController.java
private void enviaCorreo(String tipo, List<Jefe> jefes, HttpServletRequest request) throws JRException, MessagingException { log.debug("Enviando correo {}", tipo); byte[] archivo = null; String tipoContenido = null;/*from ww w .jav a 2 s. c om*/ switch (tipo) { case "PDF": archivo = generaPdf(jefes); tipoContenido = "application/pdf"; break; case "CSV": archivo = generaCsv(jefes); tipoContenido = "text/csv"; break; case "XLS": archivo = generaXls(jefes); tipoContenido = "application/vnd.ms-excel"; } MimeMessage message = mailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(message, true); helper.setTo(ambiente.obtieneUsuario().getUsername()); String titulo = messageSource.getMessage("jefe.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:MailSender.java
public void sendUserPassword(User user, String clearText) { // major: well, sender is null, so no email is going out...silently. Just a debug message. // This means that the initial configuration is not able to create a sender. // This control should no be here and the methods that handle jndi or configFile should throw a // ConfigurationException if the sender is not created. if (sender == null) { logger.debug("mail sender is null, not sending new user / password change notification"); return;//from w w w.ja va2s . co m } logger.debug("attempting to send mail for user password"); String localeString = user.getLocale(); Locale locale = null; if (localeString == null) { locale = defaultLocale; } else { locale = StringUtils.parseLocaleString(localeString); } // major: there is a bit of code duplication with the method send. // Apparently it seems that just the body is changing but the rest is // really similar. As suggested above the way a message is created should be // refactored in a collaborator. This method should just send a message. MimeMessage message = sender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(message, "UTF-8"); try { helper.setTo(user.getEmail()); helper.setSubject(prefix + " " + fmt("loginMailSubject", locale)); StringBuffer sb = new StringBuffer(); sb.append("<p>" + fmt("loginMailGreeting", locale) + " " + user.getName() + ",</p>"); sb.append("<p>" + fmt("loginMailLine1", locale) + "</p>"); sb.append("<table class='jtrac'>"); sb.append("<tr><th style='background: #CCCCCC'>" + fmt("loginName", locale) + "</th><td style='border: 1px solid black'>" + user.getLoginName() + "</td></tr>"); sb.append("<tr><th style='background: #CCCCCC'>" + fmt("password", locale) + "</th><td style='border: 1px solid black'>" + clearText + "</td></tr>"); sb.append("</table>"); sb.append("<p>" + fmt("loginMailLine2", locale) + "</p>"); sb.append("<p><a href='" + url + "'>" + url + "</a></p>"); helper.setText(addHeaderAndFooter(sb), true); helper.setSentDate(new Date()); // helper.setCc(from); helper.setFrom(from); sendInNewThread(message); // major: generic exception, method too long, I don't understand what could fail. } catch (Exception e) { logger.error("failed to prepare e-mail", e); } }
From source file:com.campodejazayeri.wedding.AdminController.java
@RequestMapping("/testmail") @ResponseBody// w ww. j av a 2 s. co 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:mx.edu.um.mateo.rh.web.VacacionesEmpleadoController.java
private void enviaCorreo(String tipo, List<VacacionesEmpleado> vacacionesEmpleados, HttpServletRequest request) throws JRException, MessagingException { log.debug("Enviando correo {}", tipo); byte[] archivo = null; String tipoContenido = null;// w w w.j a v a 2s . c om switch (tipo) { case "PDF": archivo = generaPdf(vacacionesEmpleados); tipoContenido = "application/pdf"; break; case "CSV": archivo = generaCsv(vacacionesEmpleados); tipoContenido = "text/csv"; break; case "XLS": archivo = generaXls(vacacionesEmpleados); tipoContenido = "application/vnd.ms-excel"; } MimeMessage message = mailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(message, true); helper.setTo(ambiente.obtieneUsuario().getUsername()); String titulo = messageSource.getMessage("vacacionesEmpleado.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:mx.edu.um.mateo.rh.web.CategoriaController.java
private void enviaCorreo(String tipo, List<Categoria> categorias, HttpServletRequest request) throws JRException, MessagingException { log.debug("Enviando correo {}", tipo); byte[] archivo = null; String tipoContenido = null;/*from ww w.j a va2 s . c o m*/ switch (tipo) { case "PDF": archivo = generaPdf(categorias); tipoContenido = "application/pdf"; break; case "CSV": archivo = generaCsv(categorias); tipoContenido = "text/csv"; break; case "XLS": archivo = generaXls(categorias); tipoContenido = "application/vnd.ms-excel"; } MimeMessage message = mailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(message, true); helper.setTo(ambiente.obtieneUsuario().getUsername()); String titulo = messageSource.getMessage("categoria.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:mx.edu.um.mateo.rh.web.DependienteController.java
private void enviaCorreo(String tipo, List<Dependiente> dependientes, HttpServletRequest request) throws JRException, MessagingException { log.debug("Enviando correo {}", tipo); byte[] archivo = null; String tipoContenido = null;/*from w w w .j a v a2 s .c o m*/ switch (tipo) { case "PDF": archivo = generaPdf(dependientes); tipoContenido = "application/pdf"; break; case "CSV": archivo = generaCsv(dependientes); tipoContenido = "text/csv"; break; case "XLS": archivo = generaXls(dependientes); tipoContenido = "application/vnd.ms-excel"; } MimeMessage message = mailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(message, true); String titulo = messageSource.getMessage("dependiente.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:mx.edu.um.mateo.rh.web.SolicitudVacacionesEmpleadoController.java
private void enviaCorreo(String tipo, List<SolicitudVacacionesEmpleado> vacacioness, HttpServletRequest request) throws JRException, MessagingException { log.debug("Enviando correo {}", tipo); byte[] archivo = null; String tipoContenido = null;//from w ww . j av a2s .c om switch (tipo) { case "PDF": archivo = generaPdf(vacacioness); tipoContenido = "application/pdf"; break; case "CSV": archivo = generaCsv(vacacioness); tipoContenido = "text/csv"; break; case "XLS": archivo = generaXls(vacacioness); tipoContenido = "application/vnd.ms-excel"; } MimeMessage message = mailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(message, true); helper.setTo(ambiente.obtieneUsuario().getUsername()); String titulo = messageSource.getMessage("vacaciones.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:mx.edu.um.mateo.rh.web.JefeSeccionController.java
private void enviaCorreo(String tipo, List<JefeSeccion> jefeSeccions, HttpServletRequest request) throws JRException, MessagingException { log.debug("Enviando correo {}", tipo); byte[] archivo = null; String tipoContenido = null;/*from ww w . j av a2 s.c om*/ switch (tipo) { case "PDF": archivo = generaPdf(jefeSeccions); tipoContenido = "application/pdf"; break; case "CSV": archivo = generaCsv(jefeSeccions); tipoContenido = "text/csv"; break; case "XLS": archivo = generaXls(jefeSeccions); tipoContenido = "application/vnd.ms-excel"; } MimeMessage message = mailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(message, true); helper.setTo(ambiente.obtieneUsuario().getUsername()); String titulo = messageSource.getMessage("jefeSeccion.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: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 ww w.j a v a 2 s .com 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); }