Creating an HTML Email with Images
The following code example creates an HTML email with embedded images. The content ID for an image can be a reference to a part in the email. In the following code example, the images become a part of the email and are transmitted as attachments to the email.
import PT_MCF_MAIL:*;
Local PT_MCF_MAIL:MCFOutboundEmail &email =
create PT_MCF_MAIL:MCFOutboundEmail();
&email.From = &FromAddress;
&email.Recipients = &ToList;
&email.Subject = &Subject;
Local string &htmlText =
"<html>" |
" <head><title></title></head>" |
" <body>" |
" <b>A sample jpg</b><br>" |
" <IMG SRC=cid:23abc@pc27 width=566 height=424><br>" |
" <b>End of jpg</b>" |
" </body>" |
"</html>";
/* In this sample, the htmlText is assembled using | operator
only for the readability.
Specifying just one string can be more efficient
*/
Local PT_MCF_MAIL:MCFMultipart &mp = create PT_MCF_MAIL:MCFMultipart();
&mp.SubType = "related";
Local PT_MCF_MAIL:MCFBodyPart &html = create PT_MCF_MAIL:MCFBodyPart();
&html.Text = &htmlText;
&html.ContentType = "text/html";
Local PT_MCF_MAIL:MCFBodyPart &image = create PT_MCF_MAIL:MCFBodyPart();
&image.SetAttachmentContent("///file:C:/User/Documentum/XML%20Applications/proddoc⇒
/peoplebook_upc/peoplebook_upc.dtd",
%FilePath_Absolute, "sample.jpg", "This is a sample image!", "", "");
&image.AddHeader("Content-ID", "<23abc@pc27>");
&mp.AddBodyPart(&html);
&mp.AddBodyPart(&image);
&email.MultiPart = ∓
Local integer &res = &email.Send();
Local boolean &done;
Evaluate &resp
When %ObEmail_Delivered
/* every thing ok */
&done = True;
Break;
When %ObEmail_NotDelivered
&done = False;
MessageBox(0, "", &email.MessageSetNumber, &email.MessageNumber, "PeopleTools error not found", &email.GetErrorMsgParam(1), &email.GetErrorMsgParam(2));
Break;
When %ObEmail_PartiallyDelivered
&done = True;
Break;
When %ObEmail_FailedBeforeSending
&done = False;
MessageBox(0, "", &email.MessageSetNumber, &email.MessageNumber, "PeopleTools error not found", &email.GetErrorMsgParam(1), &email.GetErrorMsgParam(2));
Break;
End-Evaluate;