To read MIME object as input stream from AWS s3 returning null

16 Views Asked by At

I'm able to retrieve the S3 contents correctly. The problem with this is when I tried converting this S3ObjectInputStream to MimeMessage by below code, I get an empty MimeMessage object.

        final GetObjectRequest request = new GetObjectRequest(bucketName, key);
        final S3Object s3Object = s3Client.getObject(request);
        S3ObjectInputStream s3ObjectInputStream = s3Object.getObjectContent();

        Properties props = new Properties();
        props.setProperty("mail.mime.allowutf8", "true");
        Session session = Session.getDefaultInstance(props);
        MimeMessage message = null;
        try {
            message = new MimeMessage(session, new BufferedInputStream(s3ObjectInputStream));

            System.out.println("-----SUBJECT: " + message.getContent());
            System.out.println("-----CONTENT: " + message.getContent());
            System.out.println("-----From ADDRESS: " + message.getFrom());
        } catch (MessagingException e) {
            throw new RuntimeException(e);
        } catch (Exception e) {
            System.out.println(e);
        } finally {
            inputStreamReader.close();
            reader.close();
        }
0

There are 0 best solutions below