while sending a mail with pdf attachment in amazon server using javamail API, Its throwing null pointer exception in the logs. But same code is working in local.
The problem may be that you can't access the URL in filePath.
Is filePath a "file:" URL? If so, why not just use a FileDataSource?
I have changed the attachment code base part as
final MimeBodyPart attachmentPart = new MimeBodyPart();
final URL url;
try {
url = new URL(filePath);
final DataSource source = new URLDataSource(url);
attachmentPart.setDataHandler(new DataHandler(source));
attachmentPart.setFileName(fileName);
attachmentPart.setDisposition(Part.ATTACHMENT);
attachmentPart.setHeader("Content-Transfer-Encoding", "base64");
multipart.addBodyPart(attachmentPart);
} catch (final MalformedURLException e) {
logger.error("Malformed URL Exception: " + e.getMessage());
}
The null pointer exception issue got resolved and got a new exception as SSLProtocol Exception and came to know the difference on java jdk's installed in both machines as 1.6 in local machine and 1.7 in amazon cloud. So followed SSL handshake alert: unrecognized_name error since upgrade to Java 1.7.0 and now the mail is triggering in both servers as expected.