Issue
Environment of work: windows 7, fedora 20, Java 7_79, maven, eclipse
EDIT
I have a web java project with maven and I'm trying to get an image that i have in src/main/resouces package to put the image on an email, this image later is set into the war at folder WEB-INF/classes/html. when run the project at windows 7 everything works fine but the problem is when i run my web project on fedora 20 (linux) i get the next error:
> 21:26:09,662 ERROR [stderr] (Thread-92) java.lang.NullPointerException
> 21:26:09,662 ERROR [stderr] (Thread-92) at
> javax.mail.internet.MimeUtility.getEncoding(MimeUtility.java:226)
> 21:26:09,663 ERROR [stderr] (Thread-92) at
> javax.mail.internet.MimeUtility.getEncoding(MimeUtility.java:299)
> 21:26:09,663 ERROR [stderr] (Thread-92) at
> javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1375)
> 21:26:09,663 ERROR [stderr] (Thread-92) at
> javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1021)
> 21:26:09,664 ERROR [stderr] (Thread-92) at
> javax.mail.internet.MimeMultipart.updateHeaders(MimeMultipart.java:419)
> 21:26:09,664 ERROR [stderr] (Thread-92) at
> javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1354)
> 21:26:09,664 ERROR [stderr] (Thread-92) at
> javax.mail.internet.MimeMessage.updateHeaders(MimeMessage.java:2107)
> 21:26:09,665 ERROR [stderr] (Thread-92) at
> javax.mail.internet.MimeMessage.saveChanges(MimeMessage.java:2075)
> 21:26:09,665 ERROR [stderr] (Thread-92) at
> javax.mail.Transport.send(Transport.java:123) 21:26:09,666 ERROR
> [stderr] (Thread-92) at
> com.acertum.serc.util.SolicitudEmail.enviarCorreo(SolicitudEmail.java:148)
> 21:26:09,666 ERROR [stderr] (Thread-92) at
> com.acertum.serc.controller.AgregarExcepcionView$1.run(AgregarExcepcionView.java:383)
this is the method that obtains the image's path
public MimeBodyPart obtenerImagen(String urlImagen) throws IOException, MessagingException{
logger.info("entro");
URL url = getClass().getClassLoader().getResource(urlImagen);
logger.info("url" + url);
MimeBodyPart attachmentPart = new MimeBodyPart();
logger.info("url.getPath()" + url.getPath().toString());
attachmentPart.attachFile(url.getPath());
attachmentPart.setDisposition(MimeBodyPart.INLINE);
return attachmentPart;
}
my principal method to send the email is the next:
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(ScoreConstants.getFromSolicitudEmail()));
message.setRecipients(Message.RecipientType.TO, recipientes);
message.setSubject(ScoreConstants.getSubjectSolicitudEmail());
String fechaSistema="<html><body><br/><br/><br/><div align='right'><h3>México,D.F a "+date+"</h3></div><br/>";
String nombreAcreditado="<br/><br/><div style='font-family: Calibri;'><strong>Acreditado: </strong> "+ acreditado +"</div><br/>";
String tipoproducto="<div style='font-family: Calibri;'><strong>Tipo de Producto: </strong>"+ subproducto +"</div><br/>";
String numeroMonto="<div style='font-family: Calibri;'><strong>Monto: </strong>"+ monto +"</div><br/>";
String descripcionExcepcion="<div style='font-family: Calibri;'><strong>Descripcion de la excepción: </strong>"+ descripcion +"</div><br/>";
String linkAceptada = "<br/><br/><br/><br/><br/><br/><br/><br/><div style='margin-left: 350px;font-family: Calibri;'><a href='http://"+ ScoreConstants.getIpServidorWeb()+":"+ScoreConstants.getPuertoServidorWeb()+"/ScoreExcepciones/AceptadoRechazado.xhtml?nombre="
+ acreditado
+ "&celular="
+ celular
+ "&fase="
+ fase
+ "&excepcionId="
+ excepcionId
+ "&subproductoId="
+ subproductoId
+ "&version="
+ version
+ "&empleadoId="
+ empleadoId
+ "&ipAddres="
+ ipAddress
+ "&accion="+autorizar+"'>Autorizar</a> "
+ " <a href='http://"+ScoreConstants.getIpServidorWeb()+":"+ScoreConstants.getPuertoServidorWeb()+"/ScoreExcepciones/AceptadoRechazado.xhtml?nombre="
+ acreditado
+ "&celular="
+ celular
+ "&fase="
+ fase
+ "&excepcionId="
+ excepcionId
+ "&subproductoId="
+ subproductoId
+ "&version="
+ version
+ "&empleadoId="
+ empleadoId
+ "&ipAddres="
+ ipAddress
+ "&accion="
+ rechazar+ "'>Rechazar</a></div>";
String cadena = String.format("%s%s%s%s%s%s%s", fechaSistema,
obtenerRutaContenido(File.separator + "html" + File.separator + "Correo.html"),
nombreAcreditado, tipoproducto, numeroMonto,
descripcionExcepcion, linkAceptada);
MimeBodyPart cadenaContenido = new MimeBodyPart();
cadenaContenido.setContent(cadena, "text/html");
String rutaPiePagina=obtenerRutaContenido((File.separator +"html" + File.separator + "PiePagina.html"));
MimeBodyPart piePagina = new MimeBodyPart();
piePagina.setContent(rutaPiePagina, "text/html");
MimeBodyPart imagenCreada=obtenerImagen(("html" + File.separator + "Logo-AcertumBank-S.jpg"));
message.setContent(ordenContenidos(imagenCreada,cadenaContenido,piePagina));
Transport.send(message);
} catch (AddressException e) {
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
e.printStackTrace(printWriter);
} catch (MessagingException e) {
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
e.printStackTrace(printWriter);
}
Solution
obtenerRutaContenido(File.separator + "html" + File.separator + "Correo.html"),
...
obtenerRutaContenido((File.separator +"html" + File.separator + "PiePagina.html"));
...
obtenerImagen(("html" + File.separator + "Logo-AcertumBank-S.jpg"));
If obtenerRutaContenido()
and obtenerImagen()
are similar you would need to start path with File.separator
too.
Answered By - CPrescott Answer Checked By - David Goodson (WPSolving Volunteer)