-2

Below is the code snippet i am trying

 Properties props = new Properties();
                Session session = Session.getDefaultInstance(props, null);
                try {
                    MimeMessage mimeMessage = new MimeMessage(session, mailFileInputStream);
                    Object content=mimeMessage.getContent();
                    BodyPart messagePart = null;
                    int count = ((Multipart) content).getCount();
                    //count is always =2
                    messagePart = ((Multipart) content).getBodyPart(0);

I tried with messagePart = ((Multipart)content).getBodyPart(1); as well because count is 2 but not able to get attachement

below is the snippet of mail coming from O365 and i am passin git here as file object.

due to securtiy reason i can not paste all here.

Some text above here
MIME-Version: 1.0

----boundary_1_768a7606-5356-4f2e-9cb9-4bcd2d468832
Content-Type: multipart/alternative;
    boundary="--boundary_0_2af5fb85-1e87-4c34-86ad-3a52ef763b25"

----boundary_0_2af5fb85-1e87-4c34-86ad-3a52ef763b25
Content-Type: text/plain; charset="iso-2022-jp"
Content-Transfer-Encoding: 7bit

-- Sent by an external sender --

----boundary_0_2af5fb85-1e87-4c34-86ad-3a52ef763b25--

----boundary_1_768a7606-5356-4f2e-9cb9-4bcd2d468832
Content-Type: multipart/mixed;
    boundary="--boundary_2_69f808df-a154-4593-ba90-6c3a570d77c8"

----boundary_2_69f808df-a154-4593-ba90-6c3a570d77c8
Content-Type: application/octet-stream; name="attachment.csv"
Content-Transfer-Encoding: base64
Content-Disposition: attachment

encryted code is comes here

----boundary_2_69f808df-a154-4593-ba90-6c3a570d77c8--

----boundary_1_768a7606-5356-4f2e-9cb9-4bcd2d468832--

I need to extract the attachment.csv file

Naveen Suryawanshi
  • 513
  • 1
  • 4
  • 15
  • I need more detail. What exactly does "not able to get" mean? What happens? What do you expect to happen? Have you read the JavaMail FAQ? In particular, [this entry about reading attachments](https://javaee.github.io/javamail/FAQ#readattach)? If you're using Office365, why are you reading the message content from a file? – Bill Shannon Nov 06 '17 at 07:02

1 Answers1

0

The message you're dealing with has a more complex structure than you're expecting. See the msgshow.java sample program for an example of how to iterate over all the message parts and extract the "attachments".

Bill Shannon
  • 29,579
  • 6
  • 38
  • 40