Discussion:
multipart/alternative emails in commerce
(too old to reply)
A***@gmail.com
2007-01-15 17:05:40 UTC
Permalink
Is it possible to send BOTH html and text versions of an email (ie,
multipart/alternative emails) using Commerce? I have looked at
SendMsgCmd, Messaging and a few other classes, but dont a way of doing
it.

Ideally, I'd like to be able to use the SendMsgCmd, along with two JSP
templates (one for text/plain and one for text/html).

I'd think sending multipart/alternative emails would be something many
companies would want to do and am surprised at the lack of
support/documentation on IBM's part.


Any pointers would be appreciated.
A***@gmail.com
2007-01-19 15:50:55 UTC
Permalink
For others who may be wondering the same, yes it is possible, but
undocumented (thanks IBM!) This solution should work in 5.5 and
apparently WCS6 as well.

To create multipart/alt emails, you create the appropriate number of
JSP templates. To obtain the results of the view execution, use this
code:

//get html content
String htmlContent = null;
String view="<viewName_html>"; //JSP template to produce html content
str

TypedProperty tp =null;
Vector formats = new Vector();
Integer emailFormat = new Integer(-3);//EMail Device FormatID
formats.add(emailFormat);
Composer composer = new Composer(view, cmdContext, tp, formats);
ComposerResult composerResult = composer.compose();
TypedProperty resultTP = composerResult.getResult();
Object obj = resultTP.get(emailFormat);

if (obj!=null && obj instanceof WCMSRecord) {
WCMSRecord wcmsRecord = (WCMSRecord) obj;
htmlContent = new String(wcmsRecord.getBytes());
}

Once you have the results if the view execution, you can use the
following code to create a MimeMultipart and use commerce's Messaging
class to send out the email.

//Use IBM's unpublished tech note code to send out mutipart/alternative
email
Messaging msg = new Messaging("<msgTypeName>", new
Integer(<storeID>));

//Create the Multipart object that you want
MimeMultipart mp = new MimeMultipart("alternative");
MimeBodyPart bp0 = new MimeBodyPart();
bp0.setDisposition(Part.INLINE);
bp0.setContent(txtContent, "text/plain");
mp.addBodyPart(bp0);

//add the plain text body part to the multipart object
MimeBodyPart bp1 = new MimeBodyPart();
bp1.setDisposition(Part.INLINE);
bp1.setContent(htmlContent, "text/html");
mp.addBodyPart(bp1);

//add the html body part to the multipart object
msg.setConfigData("recipient", "<***@address.com>");
//msg.setConfigData("CC", "<***@address.com>");
msg.setConfigData("sender", "<***@address.com>");
msg.setContent(null, "<languageID>", mp);
msg.sendImmediate();

Classes used are:
com.ibm.commerce.messaging.composer.Composer
com.ibm.commerce.messaging.composer.ComposerResult
com.ibm.commerce.messaging.outboundservice.WCMSRecord and
com.ibm.commerce.messaging.outboundservice.Messaging
Post by A***@gmail.com
Is it possible to send BOTH html and text versions of an email (ie,
multipart/alternative emails) using Commerce? I have looked at
SendMsgCmd, Messaging and a few other classes, but dont a way of doing
it.
Ideally, I'd like to be able to use the SendMsgCmd, along with two JSP
templates (one for text/plain and one for text/html).
I'd think sending multipart/alternative emails would be something many
companies would want to do and am surprised at the lack of
support/documentation on IBM's part.
Any pointers would be appreciated.
Loading...