0

I have a requirement to get the content of a email body. When I am using item.getBody().toString() method, I am getting output in HTML format , but i wanted body to be in text format. I found C# code in website but i don't know how that could be converted to java.

I have tried below approach but didn't work as expected.

PropertySet bindPropSet = new PropertySet(BasePropertySet.FirstClassProperties , EmailMessageSchema.Body);
                    bindPropSet.getRequestedBodyType();
                    BodyType body = BodyType.Text;
                    LOGGER.info(BodyType.Text);

Below is the C# code

PropertySet BindPropSet = new PropertySet(BasePropertySet.FirstClassProperties);
BindPropSet.RequestedBodyType = BodyType.Text;
Item itm = Item.bind(service, itemId, BindPropSet);
Karthik tn
  • 19
  • 8
  • I understand the c# has that feature, but what is your email email format? Could it be "multipart/alternative"? – parlad Dec 20 '18 at 16:04
  • Have you checked these links: https://stackoverflow.com/questions/3931409/mailmessage-sent-string-as-body-without-newline-in-outlook https://stackoverflow.com/questions/3288176/formatting-a-plain-text-e-mail-in-c-sharp – Alina Li Dec 21 '18 at 03:21
  • @AlinaLi I require Java code for formatting email body to text. – Karthik tn Dec 21 '18 at 05:04
  • @parladneupane mail format is multipart.. could u pls provide me the code snippet in java – Karthik tn Dec 31 '18 at 06:25
  • @LuCio could u pls look into this issue and help me out. – Karthik tn Dec 31 '18 at 06:26

1 Answers1

0

I found the solution for the above query. Below is the code snippet to have plain text format of email instead of HTML.

PropertySet psPropSet = new PropertySet(BasePropertySet.FirstClassProperties , EmailMessageSchema.MimeContent, EmailMessageSchema.ToRecipients);
psPropSet.setRequestedBodyType(BodyType.Text);
emEmailMessage = EmailMessage.bind(service, itItemId, psPropSet);
String body = emEmailMessage.getBody().toString();
Karthik tn
  • 19
  • 8