Question


Pegasystems Inc.
IN
Last activity: 24 Jul 2019 3:09 EDT
Not able to attach Corr emails as (.msg) file in work object
Hi All,
We have a requirement where during a step of a case, we are sending one corr email to user, and we are attaching the corr email in case with the help of CorrAttach activity.
Correspondence is attaching properly but when we are clicking on it we are getting a section where we can see email details.
As per client requirement, after clicking on attachment they should get email (.msg) file.
could you please suggest if we can make it with help of any pega OOTB or Java?
***Edited by Moderator Marissa to update platform capability tags****
-
Like (0)
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!


CA
Not sure if you can attach a ".msg" file but you can attach ".eml" (which also can be opened by outlook) using below Java code. Once the .eml file is downloaded to server, you can then attach it to work obkject using OOTB Activity.
//From, To, Body Subject are all String type
javax.mail.Message msg = new javax.mail.internet.MimeMessage(javax.mail.Session.getInstance(System.getProperties()));
message.setFrom(new InternetAddress(from));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));
message.setSubject(subject);
// create the message part
MimeBodyPart content = new MimeBodyPart();
// fill message; body is String type
content.setText(body);
message.writeTo(new FileOutputStream(new File("TestEmail.eml")));


Pegasystems Inc.
IN
Hi Nikhil,
Thank you for your help, i tried to used this code with correct parameter but still i am getting some issue with defining variables. Could you please suggest me any OOTB which is using the above Java code?


CA
Hi @RahulJ8221, what issues are you facing? Let me know. Are you able to atleast get the .eml file created?


Pegasystems Inc.
IN
Hi Nikhil,
i am not able to create the .eml file.
I have modified values like from, body, subject and to but not sure how to resolve below error with FileOutputStream, InternetAddress , MimeBodyPart
"FileOutputStream cannot be resolved to a type"
"MimeBodyPart cannot be resolved to a type"
"InternetAddress cannot be resolved"
Do i have to import some jar file in my application? i have saved function "SendEmailMessage" and library "Default " in our application Rule set but still i am getting the above error.
Updated: 19 Jul 2019 13:42 EDT


CA
Try below:
Try below:
javax.mail.Message message = new javax.mail.internet.MimeMessage(javax.mail.Session.getInstance(System.getProperties()));try {message.setFrom(new javax.mail.internet.InternetAddress("<your email address>"));message.setRecipients(javax.mail.Message.RecipientType.TO,javax.mail.internet.InternetAddress.parse("<your email address>"));message.setSubject("Test Email attachment to Pega work object");// create the message partjavax.mail.internet.MimeBodyPart content = new javax.mail.internet.MimeBodyPart();// fill message; body is String typecontent.setText("Hi, what's up");javax.mail.Multipart multipart = new javax.mail.internet.MimeMultipart();multipart.addBodyPart(content);message.setContent(multipart);message.writeTo(new java.io.FileOutputStream(new java.io.File("C:/Users/s2517457/PegaEmail/WOEmailAttachment.eml")));System.out.println("End of try block");} catch (Exception e) {System.out.println("In catch block");System.out.println(e.getMessage());}
***Edited by Moderator: Lochan to mask email address***


Pegasystems Inc.
IN
Hi Nikhil,
During run time below step is failing in my case and going into catch. i have setup logs error inside catch step as oLog.error(" failed went into Catch");
message.writeTo(
new java.io.FileOutputStream(new java.io.File("C:/Users/WOEmailAttachment.eml")));
oLog.error(" creating file");
System.out.println("End of try block");
Logs Entry:
2019-07-22 07:27:35,559 [fault (self-tuning)'] [ STANDARD] [ ] (ilNotification.__) ERROR setting from correctly
2019-07-22 07:27:35,559 [fault (self-tuning)'] [ STANDARD] [ ] (ilNotification.__) ERROR - setting to correctly
2019-07-22 07:27:35,558 [fault (self-tuning)'] [ STANDARD] [ ] (ilNotification.__) ERROR - setting text correctly
2019-07-22 07:27:35,558 [fault (self-tuning)'] [ STANDARD] [ ] (ilNotification.__) ERROR - setting Content correctly
2019-07-22 07:27:35,559 [fault (self-tuning)'] [ STANDARD] [ ] (ilNotification.__) ERROR - failed went into Catch


CA
@RahulJ8221 We can have a call to sort it out if you prefer.


Pegasystems Inc.
IN
Thank you Nikhil, Could you please let me know you available timings for today and tomorrow I will try to arrange some medium to connect.


Pegasystems Inc.
IN
Hi Nikhil,
thanks a lot.
The code is working when i ran in my personal machine, i guess there are folder restrictions in my project. For next step where i need to attach the file in work object, could you please give me a clue?


CA
Hi @RahulJ8221
Try below activity. Code for java step is as below:
try {
java.io.InputStream is = new java.io.FileInputStream("C:/Users/s2517457/PegaEmailTestEmail.eml");java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream(is.available());
org.apache.commons.codec.binary.Base64OutputStream baos2 = new org.apache.commons.codec.binary.Base64OutputStream(baos);
byte[] buffer = new byte[4096];
int bytesRead = 0;while ((bytesRead = is.read(buffer, 0, 4096))!=-1) {
baos2.write(buffer, 0, bytesRead);
}baos.flush();
baos.close();
is.close();ClipboardPage attachPage = tools.findPage("AttachEMLFile");
ClipboardProperty attachStream = attachPage.getProperty("pyAttachStream");
attachStream.setValue(baos.toString());
}
catch(Exception e) {
oLog.error("Unable to read file.", e);
throw new PRRuntimeException("Unable to read file.", e);
}
oLog.info("File read to clipboard successfully.");


Pegasystems Inc.
IN
Thank you so much Nikhil for your help, I really appreciate it. I will build it and get back to you with updates.