Null Pointer Exception while sending mail with attachment through JavaMail API on amazon server in Java Application

前端 未结 2 1162
暖寄归人
暖寄归人 2021-01-22 14:41

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.



        
相关标签:
2条回答
  • 2021-01-22 14:51

    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?

    0 讨论(0)
  • 2021-01-22 14:56

    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.

    0 讨论(0)
提交回复
热议问题