Creating a Multipart Email with Text and HTML Parts

The following code example creates an email with both HTML and text sections.

The email client on the target host must be able to detect the HTML and text parts in the email and display the part that the client is configured to display.

import PT_MCF_MAIL:*;

Local PT_MCF_MAIL:MCFOutboundEmail &email = 
create PT_MCF_MAIL:MCFOutboundEmail();
Local string &TestName = "Text and its alternate html body";
&email.From = &FromAddress;
&email.Recipients = &ToList;
&email.Subject = &Subject;
Local PT_MCF_MAIL:MCFBodyPart &text = create PT_MCF_MAIL:MCFBodyPart();
&text.Text = "Hi There";
Local PT_MCF_MAIL:MCFBodyPart &html = create PT_MCF_MAIL:MCFBodyPart();
&html.Text = 
"<html><BODY><H1>EMail test with HTML content</H1><b>Hi There</b>" | 
"<A href='http://www.example.com'>Check this out!</A>" |
"<P></BODY></html>";
&html.ContentType = "text/html";
Local PT_MCF_MAIL:MCFMultipart &mp = create PT_MCF_MAIL:MCFMultipart();
&mp.SubType = "alternative; differences=Content-type";
&mp.AddBodyPart(&text);
&mp.AddBodyPart(&html);
&email.MultiPart = &mp;
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;