Question
Virtusa Corporation
US
Last activity: 20 Dec 2015 22:24 EST
How to get MIME Object reference from Inbound email?
Hi,
I have a requirement to upload inbound emails received by Pega to Documentum, conditionally based on the processing of email content. To achieve this i am trying to get MIME object reference of the inbound email.
There is already a service which will support the file upload process to documentum. So i just need to get the email file and pass the content to this service.
please suggest if any thoughts.
Thanks
-
Like (0)
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Accepted Solution
Pegasystems Inc.
CA
As Jeff mentioned, if you have configured your Email listener to store the original email as attachment to your case, you already have the .eml file which you can send to your service. Doesn't this work? For some reason, if you want the email content as a MimeMessage object, you can see the example in this post to convert the .eml file into a MimeMessage object. http://stackoverflow.com/questions/2781739/loading-eml-files-into-javax-mail-messages
Pegasystems Inc.
US
Please post this question to the Pega Product Support space: Pega Product Support
Virtusa Corporation
US
Thanks John, changed the place.
Pegasystems Inc.
US
What do you mean by "MIME Object reference ?"
Are you referring to Java Mail objects like these: MimeMessage (Java(TM) EE 7 Specification APIs) ?
Virtusa Corporation
US
Thanks for the reply Jeff. Yes i want to get handle(object reference) of the email message. Goal is to send this email to documentam. if i can get the object reference of the email then will be able to get file content and details to send it to Service.
You can use the MimeMessage API as Jeff mentioned, specially you want to use getContent() which will return the content as Java object and then you can check its it of type string or else its multipart. Below is the sample code you can try:
You can use the MimeMessage API as Jeff mentioned, specially you want to use getContent() which will return the content as Java object and then you can check its it of type string or else its multipart. Below is the sample code you can try:
private String getContent(Part p) throws MessagingException, IOException { String finalContents = ""; if (p.getContent() instanceof String) { finalContents = (String) p.getContent(); } else { Multipart mp = (Multipart) p.getContent(); if (mp.getCount() > 0) { Part bp = mp.getBodyPart(0); try { finalContents = dumpPart(bp); } catch (Exception e) { e.printStackTrace(); } } } return finalContents.trim(); } private String dumpPart(Part p) throws Exception { InputStream is = p.getInputStream(); if (!(is instanceof BufferedInputStream)) { is = new BufferedInputStream(is); } return getStringFromInputStream(is); } private String getStringFromInputStream(InputStream is) { BufferedReader br = null; StringBuilder sb = new StringBuilder(); String line; try { br = new BufferedReader(new InputStreamReader(is)); while ((line = br.readLine()) != null) { sb.append(line); sb.append("\n"); } } catch (IOException e) { e.printStackTrace(); } finally { if (br != null) { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } } return sb.toString(); }
FYI: If you add DEBUG on "com.pega.pegarules.integration.engine.internal.services.email.EmailListener" class, you can see the MIME type used by incoming email in the PegaRULES log.
Updated: 16 Nov 2015 14:15 EST
Pegasystems Inc.
US
I think the customer is asking for a handle back from Pega. The data returned by Pega is not a Part nor an InputStream.
Should there be a product enhancement to create this call back handle to send the email message object?
Updated: 16 Nov 2015 14:14 EST
Pegasystems Inc.
US
Is your application configured to attach copies of inbound email messages to cases?
The emails are attached as binary representations of the message.
Perhaps these could be used for your needs?
Accepted Solution
Pegasystems Inc.
CA
As Jeff mentioned, if you have configured your Email listener to store the original email as attachment to your case, you already have the .eml file which you can send to your service. Doesn't this work? For some reason, if you want the email content as a MimeMessage object, you can see the example in this post to convert the .eml file into a MimeMessage object. http://stackoverflow.com/questions/2781739/loading-eml-files-into-javax-mail-messages
Virtusa Corporation
US
Thank You Praneeth , Jeff and Aditya for the suggestions. Sorry for the delay in my response.
As Praneeth mentioned simple and best way to solve my problem was attaching the email back to the work object. so that we can pass the content of the email to service from work object attachments.