Question
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
Capgemini
IN
Last activity: 7 Feb 2017 8:39 EST
@base class sendemailnotification activity is not working properly in pega 7.1.6 & 7.1.5
Hello Team,
We are trying to run @base class sendemailnotification activity manually by giving the parameters & its not working properly in pega 7.1.6 & 7.1.5, and working as expected in pega 7.1.7
We have provided TO,From, smtphost, subject & body in the parameters, & body is missing in the delivered email as shown below. And it is working in pega 6.2,6.3 & 7.1.7.
Please help us to get the issue addressed.
Thanks for your help.
PFB screenshot references for the issue.
Thanks,
Rohith Reddy
Capgemini
-
Like (0)
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
![](/themes/custom/pegacc_theme/images/user-icon.png)
![](/themes/custom/pegacc_theme/images/user-icon.png)
The screenshots are not clear so I can't tell what the error is. I also suggest Tracing the execution and comparing it to a working scenario to figure out where the problem lies.
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
Aaseya IT services
IN
The actual issue is we are able to send the email but the body of email is missing.
![](/themes/custom/pegacc_theme/images/user-icon.png)
![](/themes/custom/pegacc_theme/images/user-icon.png)
We have seen issues like this for EmailListener but I don't recall such a problem with sendemailnotification. Regardless, Tracer is your friend and you can turn debug on sendemailmessage RUF/RUL for javamail debug.
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
Capgemini
IN
Thanks Vipin for your suggestions. But we have already tried to trace the activity, but didn't see any issues/errors on it.
![](https://accounts.pega.com/sites/default/files/pega-user-image/35/REG-34624.png?source=PUMINIT)
![](https://accounts.pega.com/sites/default/files/pega-user-image/35/REG-34624.png?source=PUMINIT)
Pegasystems Inc.
GB
Firstly: I would advise that since this works on 717 - but you report that you find that it doesn't work on lower 7 versions: the obvious question is - why not use 717 I guess ?
But assuming for some reason you cannot:
You could try enabling the underlying Java Mail Debug for this.
For my example here, I happen to be using 717 - so just be careful to check on whatever version you are trying to debug that everything below applies to your version as well.
The work done by the Activity SendEmailNotification is actually mostly done in the function "pega_integrationengine_default.SendEmailMessage"
Within that function, there is a switch will enable the underlying Java Mail API debugging (as well as it's own debugging lines):
if( oLog.isDebugEnabled()){ props.put("mail.debug", "true"); }
So: using SMA, you can switch on DEBUG logging for the library which contains this Function (The Library is called 'Default' - which can be seen on the Rule Form for the Function):
Firstly: I would advise that since this works on 717 - but you report that you find that it doesn't work on lower 7 versions: the obvious question is - why not use 717 I guess ?
But assuming for some reason you cannot:
You could try enabling the underlying Java Mail Debug for this.
For my example here, I happen to be using 717 - so just be careful to check on whatever version you are trying to debug that everything below applies to your version as well.
The work done by the Activity SendEmailNotification is actually mostly done in the function "pega_integrationengine_default.SendEmailMessage"
Within that function, there is a switch will enable the underlying Java Mail API debugging (as well as it's own debugging lines):
if( oLog.isDebugEnabled()){ props.put("mail.debug", "true"); }
So: using SMA, you can switch on DEBUG logging for the library which contains this Function (The Library is called 'Default' - which can be seen on the Rule Form for the Function):
The logger is called 'com.pegarules.generated.pega_integrationengine_default' - switch this to DEBUG.
Now: here's the other issue - the DEBUG output for the JavaMail API goes to 'standardout' : so you need to know where your particular App Server redirects this information - as that it where you'll need to look for the DEBUG output.
If you are on Tomcat - I have never been able to work out where this information goes - so I have taken a different approach.
If you are in this position of using Tomcat - and you can't find where it puts it's standard-out (and if you DO find this out , please let us know how and where you found it !); then you can do the following:
A. Create your own Function Rule:
1. Create your OWN Function Library ('MyDiagnostic' or something).
2. Create your OWN Function in this library called SendEmailMessage (not strictly necessary to have the same name as the original, but why not).
3. Copy the existing OOTB SendEmailMessage Java code into your function.
4. At the top of the pasted code, add in a 'oLog.infoForced("diagnostic called");' - just something that will appear in your PegaRules.log to prove you are picking up the right function when you come to test it.
4. Save your Function, Build the Library - make sure there are no errors.
B. Perform a Private CheckOut of the OOTB Activity - reference your function
1. Perform a Private Checkout of the calling Activity SendEmailNotification.
2. Change the Java Step (it's step 6 in the PRPC717 version) to reference YOUR function library/function.
C. Test it.
1. Just perform your test as before: confirm you see the DEBUG logging you added into your Function.
D. Modify your Function to 'catpure' the log.
This is tricky part: you might find that you have to edit this code below in order to get it to 'fit' your PRPC Version.
This works for 717 (but of course that is the one version you do NOT need to debug !):
The code does the following :
It creates an 'OutputStream' which just captures anything sent to it into a StringBuilder.
We then re-direct the Java Mail API to use this 'OutputStream'; this is done by modifying the existing code to do this:
if( oLog.isDebugEnabled() ) { smtpcapturelog=new SMTPLogCaptureLog( new CapturingOutputStream() ); session.setDebugOut( smtpcapturelog ); session.setDebug( true ); Properties sessionprops=session.getProperties(); sessionprops.list( smtpcapturelog ); }
Once we have finished, we need to flush the StringBuilder - we just output it to the standard PegaRules logs (by performing an 'oLog.debug' of the output itself).
Of course you also have to enable the same DEBUG options in SMA as before (or you could modify the code above just to always output at DEBUG if you prefer).
This is an example of the output:
2015-08-17 15:01:30,152 [ttp-bio-7170-exec-12] [TABTHREAD8] [ | ] [ GCSAppli:01.01.01] (les.generated.gcsappli_gcsdiag) DEBUG prpchost|xx.xx.xx.xx Admin@gcs - START SMTP LOG |
DEBUG: setDebug: JavaMail version 1.4.1
-- listing properties --
mail.smtp.port=25
mail.smtp.auth=true
mail.smtp.localhost=prpchost.pega.com
mail.smtp.timeout=60000
mail.smtp.sendpartial=true
mail.smtp.connectiontimeout=60000
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "prpchost", port 25, isSSL false
220 prpchost SMTP Server (JAMES SMTP Server 2.3.2) ready Fri, 7 Aug 2015 15:04:30 +0100 (BST)
DEBUG SMTP: connected to host "prpchost", port: 25
EHLO prpchost.pega.com
250-prpchost Hello prpchost.pega.com (prpchost.pega.com [xx.xx.xx.xx])
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250-PIPELINING
250 ENHANCEDSTATUSCODES
DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN"
DEBUG SMTP: Found extension "AUTH=LOGIN", arg "PLAIN"
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Attempt to authenticate
AUTH LOGIN
334 VXNlcm5hbWU6
cmVk
334 UGFzc3dvcmQ6
cmVk
235 Authentication Successful
DEBUG SMTP: use8bit false
MAIL FROM:<red@prpchost>
250 2.1.0 Sender <red@prpchost> OK
DEBUG SMTP: sendPartial set
RCPT TO:<red@prpchost>
250 2.1.5 Recipient <red@prpchost> OK
DEBUG SMTP: Verified Addresses
DEBUG SMTP: red@prpchost
DATA
354 Please start mail input.
Date: Fri, 7 Aug 2015 15:04:30 +0100 (BST)
From: red <red@prpchost>
Reply-To: red@prpchost
To: red@prpchost
Message-ID: <809479554.62.1438956270351.JavaMail.user@prpchost>
Subject: Test From Flow
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_61_1125857553.1438956270336"
Thread-Topic: (()Test From Flow) Test From Flow
------=_Part_61_1125857553.1438956270336
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: 7bit
<HTML>
<HEAD>
<TITLE>
Test From Flow
</TITLE>
</HEAD>
<BODY>
<div style="font-family:courier new;font-size:10.0pt;"><div style="text-align: right;">Pegasystems European HQ<br />One Reading Central<br />3rd Floor<br />23 Forbury Road<br />Reading<br />Berkshire<br />RG1 3JH<br />UK<br /> </div><div> </div>Date:07/08/2015<br /><br />Dear Whoever,<br /><br />Something blah blah yadda yadda.<br /><br />I hope to hear from you soon in this matter,<br /><br /><br />Cheers Pega.</div>
</BODY>
</HTML>
------=_Part_61_1125857553.1438956270336--
.
250 Mail queued for delivery.
QUIT
221 Closing connection. Good bye.
END SMTP LOG
The modified code is below - but I'll attach the same code as well, to avoid any copy/paste rage here: Remember this is from 717 - so you might have to make some adjustments to suit your version.
oLog.infoForced("****************** DIAG 'SendEmailMessage' ***************** DEBUG logging is :" + oLog.isDebugEnabled() ); final class CapturingOutputStream extends java.io.OutputStream { private StringBuilder string = new StringBuilder(); public void write(int b) throws java.io.IOException { this.string.append((char) b); } public String toString() { return this.string.toString(); } }; final class SMTPLogCaptureLog extends java.io.PrintStream { private OutputStream os; SMTPLogCaptureLog(OutputStream os) { super( os ); this.os=os; oLog.debug("MailCaptureLog instance created"); } void outputToLogAndCloseStreams() { oLog.debug( "START SMTP LOG\n"+this.os.toString()+"\nEND SMTP LOG"); try { this.os.close(); this.close(); } catch(Exception e) { oLog.error(e); } } }; SMTPLogCaptureLog smtpcapturelog=null; PublicAPI tools = null; PRThread thisThread = (PRThread)ThreadContainer.get(); if (thisThread != null) { tools = thisThread.getPublicAPI(); } else { throw new PRAppRuntimeException("Pega-ProCom", 0, "Unable to obtain current thread."); } PegaAPI pegaAPI = (PegaAPI)tools; com.pega.pegarules.pub.util.ServiceUtils svcUtils = pegaAPI.getServiceUtils(); com.pega.pegarules.priv.util.ServiceUtilsPriv svcUtilsPriv = pegaAPI.getServiceUtilsPriv(); //Extract email message data // BUG-74284: attempt to obtain all messages values indirectly. String smtpHost = svcUtilsPriv.getStringIndirect(MessageData, "pysmtpHost"); String smtpUserID = svcUtilsPriv.getStringIndirect(MessageData, "pyFromUserID"); // get property value for password String smtpPassword = MessageData.getString("pyFromPassword"); // BUG-99388 smtpPassword = svcUtils.resolvePassword(smtpPassword, MessageData); // boolean value is not obtained indirectly. boolean useSSL = MessageData.getBoolean("pyUseSSL"); String fromName = svcUtilsPriv.getStringIndirect(MessageData, "pyFromFullName"); String fromAddr = svcUtilsPriv.getStringIndirect(MessageData, "pyFrom"); String replyTo = svcUtilsPriv.getStringIndirect(MessageData, "pyReplyTo"); String recipTo = svcUtilsPriv.getStringIndirect(MessageData, "pyToString"); String recipCC = svcUtilsPriv.getStringIndirect(MessageData, "pyCCString"); String recipBCC = svcUtilsPriv.getStringIndirect(MessageData, "pyBCCString"); String msgPriority = svcUtilsPriv.getStringIndirect(MessageData, "pyPriority"); String msgSubject = svcUtilsPriv.getStringIndirect(MessageData, "pySubject"); String msgBodyText = svcUtilsPriv.getStringIndirect(MessageData, "pyBody"); String emailType = svcUtilsPriv.getStringIndirect(MessageData, "pyEmailType"); String attachmentPageName = svcUtilsPriv.getStringIndirect(MessageData, "pyAttachmentPageName"); String keystoreInstance = svcUtilsPriv.getStringIndirect(MessageData, "pyKeystoreInstance"); String keystoreAlias = svcUtilsPriv.getStringIndirect(MessageData, "pyKeystoreAlias"); // boolean values not obtained indirectly boolean encrypt = MessageData.getBoolean("pyEncryptMessage"); boolean isTestConnectivity = MessageData.getBoolean("pyIsTestConnectivity"); String smtpPort = svcUtilsPriv.getStringIndirect(MessageData, "pysmtpPort"); //boolean sign = MessageData.getBoolean("pySignEmail"); // HFix-8559, BUG-135287: Check if charset is set, if not, default to UTF-8 String charset = svcUtilsPriv.getStringIndirect(MessageData, "pyCharset"); if (charset == null || charset.length() == 0) charset = "UTF-8"; MessageData.getProperty("pyRecoverableError").setValue(0); try { // BURND: See attachment id handling with Thread Topic when attachment support is added. ClipboardPage attachmentPage = tools.findPage(attachmentPageName); // If this is an HTML message, ensure proper formatting if( emailType.equalsIgnoreCase("HTML") ){ if(! ((msgBodyText.indexOf("<html") != -1) || (msgBodyText.indexOf("<HTML") != -1)) ){ String bodyTemp = ""; bodyTemp += "<HTML>\n"; bodyTemp += "<HEAD>\n"; bodyTemp += "<TITLE>\n"; bodyTemp += msgSubject + "\n"; bodyTemp += "</TITLE>\n"; bodyTemp += "</HEAD>\n"; bodyTemp += "<BODY>\n"; bodyTemp += msgBodyText + "\n"; bodyTemp += "</BODY>\n"; bodyTemp += "</HTML>\n"; msgBodyText = bodyTemp; } } // // Create the session object // /* create properties object for Java Mail API */ Properties props = new Properties(); // provider as defined in mail API: "smtp" or "smtps" String provider = "smtp"; // the prefix for properties, matching the "provider" String propPrefix = "mail." + provider + "."; if (useSSL) { // modify provider and prefix to match SSL state provider = "smtps"; propPrefix = "mail." + provider + "."; props.put(propPrefix + "socketFactory.class", "javax.net.ssl.SSLSocketFactory"); props.put(propPrefix + "socketFactory.fallback", "false"); } // BUG-91543: set timeouts String emailTimeout = "60000"; String timeoutDSS = tools.getSystemSettings().getDynamic("Pega-IntSvcs","email/timeout"); int customTimeout = -1; try { customTimeout = Integer.parseInt(timeoutDSS); } catch (Exception ex) { customTimeout = -1; } if (customTimeout > 0) emailTimeout = timeoutDSS; // IO timeouts props.put(propPrefix + "timeout", emailTimeout); // connection timeouts props.put(propPrefix + "connectiontimeout", emailTimeout); // BUG-84682: allow default security settings to be overridden - should configure app server trust store instead. String strDisableSecurity = tools.getSystemSettings().getDynamic("Pega-IntSvcs","Email/DisableSecuritySTARTTLS"); boolean disableSecurity = Boolean.parseBoolean(strDisableSecurity); if (! disableSecurity) { // allow STARTTLS when server can do it props.put(propPrefix + "starttls.enable", "true"); } // use FQDN, per SMTP spec String fqdn = java.net.InetAddress.getLocalHost().getCanonicalHostName(); props.put(propPrefix + "localhost", fqdn); //Bug-18904 : set the property called mail.smtp.sendpartial to true props.put(propPrefix + "sendpartial", "true"); props.put(propPrefix + "auth", "true"); if (smtpPort !=null && !(smtpPort.equals(""))){ props.put(propPrefix + "port", smtpPort); } /* End of entries for Properties object */ Session session = Session.getInstance(props); if( oLog.isDebugEnabled() ) { smtpcapturelog=new SMTPLogCaptureLog( new CapturingOutputStream() ); session.setDebugOut( smtpcapturelog ); session.setDebug( true ); Properties sessionprops=session.getProperties(); sessionprops.list( smtpcapturelog ); } MessageData.getProperty("pyIsSessionEstablished").setValue(true); MimeMessage message = new MimeMessage(session); javax.mail.Multipart multipart = new javax.mail.internet.MimeMultipart(); // add message body MimeBodyPart msgBodyPart = new MimeBodyPart(); if( emailType.equals("HTML") ){ msgBodyPart.setContent(msgBodyText, "text/html; charset=\"" + charset + "\""); }else{ msgBodyPart.setContent(msgBodyText, "text/plain; charset=\"" + charset + "\""); } multipart.addBodyPart(msgBodyPart); // Set "From" fields if (fromName.length() > 0) message.setFrom(new InternetAddress(fromAddr, fromName,charset)); else message.setFrom(new InternetAddress(fromAddr)); if (replyTo.length() > 0) message.setReplyTo(InternetAddress.parse(replyTo)); // Set "To" fields if(recipTo.length()>0){ recipTo = recipTo.replaceAll(";",","); InternetAddress[] recipToAdd= InternetAddress.parse(recipTo); for(int i=0; i<recipToAdd.length;i++){ String toAddress= recipToAdd[i].getAddress(); String toName = recipToAdd[i].getPersonal(); recipToAdd[i]= new InternetAddress(toAddress,toName ,charset); } message.setRecipients(Message.RecipientType.TO,recipToAdd); } if (recipCC.length() > 0){ recipCC= recipCC.replaceAll(";",","); InternetAddress[] recipCCAdd= InternetAddress.parse(recipCC); for(int i=0; i<recipCCAdd.length;i++){ String ccAddress= recipCCAdd[i].getAddress(); String ccName = recipCCAdd[i].getPersonal(); recipCCAdd[i]= new InternetAddress(ccAddress,ccName,charset); } message.setRecipients(Message.RecipientType.CC, recipCCAdd); } if (recipBCC.length() > 0){ recipBCC= recipBCC.replaceAll(";",","); InternetAddress[] recipBCCAdd= InternetAddress.parse(recipBCC); for(int i=0; i<recipBCCAdd.length;i++){ String bccAddress = recipBCCAdd[i].getAddress(); String bccName = recipBCCAdd[i].getPersonal(); recipBCCAdd[i]= new InternetAddress(bccAddress,bccName,charset); } message.setRecipients(Message.RecipientType.BCC,recipBCCAdd); } // Set the message priority if (msgPriority.equalsIgnoreCase("HIGH")) message.addHeader("X-Priority", "1"); else if (msgPriority.equalsIgnoreCase("LOW")) message.addHeader("X-Priority", "5"); // Set the message subject - may not contain new-line characters message.setSubject(msgSubject.replace('\n', ' '), charset); /* Handle iCalendar meeting requests ClipboardProperty meetingDataRef = MessageData.getProperty("pyMeetingData"); if (!meetingDataRef.isEmpty()) { // Add a header for the message.addHeader("component", "VEVENT"); // Format the meeting data into a string String meetingData = FormatMeetingRequest(meetingDataRef.getPageValue()); MimeBodyPart meetingPart = new MimeBodyPart(); meetingPart.setDataHandler(new DataHandler( new javax.mail.util.ByteArrayDataSource(meetingData, "text/calendar"))); multipart.addBodyPart(meetingPart); } */ //GOLOD: Added support for attachments String attachId = null; BodyPart messageBodyPart = new MimeBodyPart(); if ((attachmentPage != null) && (attachmentPage.getProperty("pyAttachments") !=null) && (attachmentPage.getProperty("pyAttachments").size() !=0)){ ClipboardProperty attsprop = attachmentPage.getProperty("pyAttachments"); String tempdir = tools.getProperty("pxProcess.pxTempPath").getStringValue(); tempdir += PRFile.separatorChar; // process list of attachments - 1st write to a file for (int i = 1; i <= attsprop.size(); i++) { ClipboardPage attach = attsprop.getPageValue(i); String propref = attach.getString("pyReference"); boolean decode = attach.getBoolean("pyDecode"); boolean removexml = attach.getBoolean("pyRemoveXML"); String attname = attach.getString("pyName"); //BUG-152335: added code to encode the attachment name attname = javax.mail.internet.MimeUtility.encodeText(attname,charset,null); String atttype = attach.getString("pyType"); String cid = attach.getString("pyContentID"); String encodedData = attach.getString("pyData"); //save attachid if (cid!=null && !cid.equals("")) { if (attachId==null) attachId=cid; else attachId+=","+cid; } // name the attachment, append type if present, append 'htm' to url's if (atttype.length() > 0) { if (!atttype.equalsIgnoreCase("url")) { attname = attname + "." + atttype; } else { attname = attname + ".htm"; } } if (propref.length() > 0 || (encodedData!=null&&encodedData.length()>0)) { // get the contents of the attachment String content = null; if (propref.length()>0) { ClipboardProperty contentprop = tools.getProperty(propref); content = contentprop.getStringValue(); } else { content = encodedData; } byte decodedBuffer [] = null; if (content.length() > 0) { messageBodyPart = new MimeBodyPart(); DataSource source = null; // check for url //String temp = content.substring(0, 10); String temp = ""; if ( content.length() >= 10) temp = content.substring(0, 10); else temp = content.substring(0,content.length()); temp = temp.toLowerCase(); if (temp.startsWith("http://") || temp.startsWith("https://") || atttype.equalsIgnoreCase("url")) { source = new URLDataSource(new java.net.URL(content)); } else { if (removexml) { int pos = content.indexOf("<pagedata"); if (pos > -1) { pos = content.indexOf("><", pos + 1); if (pos > -1) { pos = content.indexOf(">", pos + 1); if (pos > -1) { int spos = pos + 1; pos = content.indexOf("</", spos); if (pos > -1) { content = content.substring(spos, pos); } } } } } if (!decode) { decodedBuffer = content.getBytes(); } else { // try decoding the data java.io.ByteArrayOutputStream outByteStream = new java.io.ByteArrayOutputStream(); java.io.OutputStream outStream = new java.io.BufferedOutputStream(outByteStream); try { byte[] inText = content.getBytes(); java.io.ByteArrayInputStream inByteStream = new java.io.ByteArrayInputStream(inText); java.io.InputStream inStream = new java.io.BufferedInputStream(inByteStream); java.io.InputStream encStream = Base64Util.decode(inStream); java.io.DataInputStream disStream = new java.io.DataInputStream(encStream); byte[] buffer = new byte[4096]; int len; while ((len = disStream.read(buffer)) != -1) { outStream.write(buffer, 0, len); } if (disStream != null) { disStream.close(); } } catch (Exception e) { String strStatus = ""; strStatus = "Error decoding Attachment: " + e.toString(); oLog.error(strStatus); } try { if (outStream != null) { outStream.flush(); // store the decoded data into a buffer decodedBuffer = outByteStream.toByteArray(); outStream.close(); } } catch (Exception e) { String strStatus = ""; strStatus = "Error decoding Attachment: " + e.toString(); oLog.error(strStatus); } } source = new javax.mail.util.ByteArrayDataSource(decodedBuffer, javax.activation.FileTypeMap.getDefaultFileTypeMap().getContentType(attname)); } // add attachment to multipart messageBodyPart.setFileName(attname); messageBodyPart.setDataHandler(new DataHandler(source)); if (cid!=null && !cid.equals("")) messageBodyPart.setHeader("Content-ID", cid); multipart.addBodyPart(messageBodyPart); } } } } // Handle any user specified email headers. // ClipboardProperty emailHeaders = null; if (attachmentPage != null) { emailHeaders = attachmentPage.getProperty("pyEmailHeaders"); } // Special case Thread-Topic header. If this is found, append attachId and email subject. // This is used to send the workobject id so that any DSN's can be traced back. if (emailHeaders != null && emailHeaders.size() > 0) { int cnt = emailHeaders.size(); for (int indx = 1; indx <= cnt; indx++) { ClipboardPage aHead = emailHeaders.getPageValue(indx); if (aHead.getString("pyName").equals("Thread-Topic")) { if (attachId==null) { message.addHeader(aHead.getString("pyName"),"("+aHead.getString("pyValue")+") "+msgSubject); } else { message.addHeader(aHead.getString("pyName"),"("+aHead.getString("pyValue")+";"+attachId+") "+msgSubject); } } else { message.addHeader(aHead.getString("pyName"),aHead.getString("pyValue")); } } } if (attachId != null){ message.addHeader("X-PegaAttachmentID", attachId); String strAddLegacyHeaders = tools.getSystemSettings().getDynamic("Pega-IntSvcs","Email/AddLegacyHeaders"); boolean addLegacyHeaders = Boolean.parseBoolean(strAddLegacyHeaders); if (addLegacyHeaders) { message.addHeader("PegaAttachmentID", attachId); } } // Set the message content message.setContent(multipart); // Set the sent date timestamp message.setSentDate(new Date()); // // Set up e-mail signing and/or encryption // if ( !keystoreInstance.equals("") ){ try{ // get the Certificate from the keystore HashStringMap certStrMap = new HashStringMap(); certStrMap.putString("pyActivityName", "getCertificate"); certStrMap.putString("pyClassName", "Data-Admin-Security-Keystore"); tools.doActivity(certStrMap, null, null); ParameterPage pp = tools.getParameterPage(); Certificate [] certChain = (Certificate[]) pp.getParameterValue("CertificateChain"); Key certKey = (Key) pp.getParameterValue("CertificateKey"); /// Create CertStore for signature's cert chain List myCertList = new ArrayList(); oLog.info("Certificate Chain size: " + certChain.length); for( int i=0; i < certChain.length; i++ ){ myCertList.add(certChain[i]); } CertStore certsAndCRLs = CertStore.getInstance( "Collection", new CollectionCertStoreParameters(myCertList), "BC"); /// Create SMIME capabilities in case someone wants to respond org.bouncycastle.asn1.ASN1EncodableVector signedAttrs = new org.bouncycastle.asn1.ASN1EncodableVector(); org.bouncycastle.asn1.smime.SMIMECapabilityVector caps = new org.bouncycastle.asn1.smime.SMIMECapabilityVector(); caps.addCapability(org.bouncycastle.asn1.smime.SMIMECapability.dES_EDE3_CBC); caps.addCapability(org.bouncycastle.asn1.smime.SMIMECapability.rC2_CBC, 128); caps.addCapability(org.bouncycastle.asn1.smime.SMIMECapability.dES_CBC); signedAttrs.add(new org.bouncycastle.asn1.smime.SMIMECapabilitiesAttribute(caps)); // Create the signed message generator org.bouncycastle.mail.smime.SMIMESignedGenerator SMIMEgen = new org.bouncycastle.mail.smime.SMIMESignedGenerator(); Certificate myCert = certChain[0]; SMIMEgen.addSigner((PrivateKey)certKey, (X509Certificate)myCert, org.bouncycastle.mail.smime.SMIMESignedGenerator.DIGEST_SHA1, new org.bouncycastle.asn1.cms.AttributeTable(signedAttrs), null); SMIMEgen.addCertificatesAndCRLs(certsAndCRLs); // Sign the message MimeMessage signedMessage = new MimeMessage(session); multipart = SMIMEgen.generate(message, "BC"); Enumeration headers = message.getAllHeaderLines(); while (headers.hasMoreElements()) { signedMessage.addHeaderLine((String)headers.nextElement()); } signedMessage.setContent(multipart); message = signedMessage; }catch (Exception Any){ String strStatus = "SendEmailMessage: Could not set up e-mail signing: \n" + Any.toString(); oLog.error(strStatus); return strStatus; } } if(encrypt) { try { HashStringMap aliasMap = new HashStringMap(); aliasMap.putString("pyActivityName", "pyGetEmailCertificates"); aliasMap.putString("pyClassName", "Data-Admin-Security-Keystore"); ParameterPage pp = new ParameterPage(); pp.putParamValue("EmailAddress", recipTo); tools.doActivity(aliasMap, null, pp); ArrayList certChain2 = (ArrayList) pp.getParameterValue("CertificateChain"); // Create the encrypter SMIMEEnvelopedGenerator encrypter = new SMIMEEnvelopedGenerator(); for (int i = 0; i < certChain2.size(); i++) { encrypter.addKeyTransRecipient((X509Certificate)(certChain2.get(i))); } // Encrypt the message MimeBodyPart encryptedPart = encrypter.generate(message, SMIMEEnvelopedGenerator.RC2_CBC, "BC"); /* * Create a new MimeMessage that contains the encrypted and signed * content */ ByteArrayOutputStream out = new ByteArrayOutputStream(); encryptedPart.writeTo(out); MimeMessage encryptedMessage = new MimeMessage(session, new ByteArrayInputStream(out.toByteArray())); /* Set all original MIME headers in the encrypted message */ Enumeration headers = message.getAllHeaderLines(); while (headers.hasMoreElements()) { String headerLine = (String)headers.nextElement(); /* * Make sure not to override any content-* headers from the * original message */ if (!Strings.toLowerCase(headerLine).startsWith("content-")) { encryptedMessage.addHeaderLine(headerLine); } } message = encryptedMessage; }catch (Exception Any){ String strStatus = "SendEmailMessage: Could not set up e-mail encryption: \n" + Any.toString(); oLog.error(strStatus); return strStatus; } } // // Open the SMTP connection and send the message // Transport transport = session.getTransport(provider); MessageData.getProperty("pyIsTransportAcquired").setValue(true); transport.connect(smtpHost, smtpUserID, smtpPassword); MessageData.getProperty("pyIsConnected").setValue(true); try { if (!isTestConnectivity){ transport.sendMessage(message, message.getAllRecipients()); // add header for PRPC purposes - not included in sent message. if (emailHeaders != null) { ClipboardPage messageIDHeader = thisThread.createPage("Data-Email-Header", null); messageIDHeader.putString("pyName", "Message-ID"); messageIDHeader.putString("pyValue", message.getMessageID()); if (oLog.isDebugEnabled()) { oLog.debug("Message-ID:" + message.getMessageID()); } emailHeaders.add(messageIDHeader); } } } finally { if (transport != null) transport.close(); MessageData.getProperty("pyIsDisconnectedSuccessfully").setValue(true); } } catch (Exception e) { if (isTestConnectivity){ oLog.error("Exception caught while testing connection to " + smtpHost + " as user " + fromAddr, e); } else { oLog.error("Unexpected exception caught while trying to send an email message.", e); oLog.error("Failing message has sender ID of <" + fromAddr + "> and addressee of <" + recipTo + ">."); } String msg = "Caught " + e.getClass().getName(); Throwable cause = e.getCause(); if (e.getMessage() != null && cause != null && cause.getMessage() != null) { msg = msg + ", " + e.getMessage(); if ((msg.toLowerCase().indexOf("could not connect to smtp host") >= 0) || (cause.getMessage().toLowerCase().indexOf("connection reset") >= 0)) MessageData.getProperty("pyRecoverableError").setValue(1); else MessageData.getProperty("pyRecoverableError").setValue(-1); oLog.error("Setting pyRecoverableError property to " + MessageData.getInteger("pyRecoverableError")); } MessageData.putObject("pyEmailException", e); return msg; } finally { if (smtpcapturelog!=null) { smtpcapturelog.outputToLogAndCloseStreams(); } } return "";
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
AdeptView
NL
Hi,
I am not getting values for Thread-Topic even though it is mapped in requester tab. Any idea?