Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Internet Protocols Module User's Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

9.5 Program: Creating a Multipart MIME Message

Example 28 presents a complete program that creates a multipart MIME message. The program creates a multipart message that contains the same text in three formats: unencoded, base 64 encoded, and quoted-printable encoded. Source code for this program is located in MultipartMimeMessageComposition.cpp in the examples\mime directory.


NOTE -- Sample programs are located in the examples directory created for your installation. For more information, see Installing and Building Your SourcePro C++ Products and Building Your Applications.

Example 28: Creating a multipart MIME message

//1Creates an RWMimeTextType for the value "text/plain".
//2Constructs a Content-Transfer-Encoding header for base 64 encoding.
//3Constructs a Content-Transfer-Encoding header for quoted-printable encoding.
//4Constructs the string that forms the basic content for each part of the multipart message.
//5Converts the content string to canonical form.
//6Encodes the content string using base 64 encoding and stores the result in a new string.
//7Encodes the content string using quoted-printable encoding and stores the result in a new string.
//8Constructs three new RWMimePart objects. Each object has a Content-Type header with the value textType.
//9Sets the body of the first MIME part to the unencoded content.
//10Inserts the Content-Transfer-Encoding header for base 64 encoding into the second MIME part.
//11Sets the body of the second MIME part to the base 64 encoded content.
//12Inserts the Content-Type header for text/plain into the third MIME part.
//13Inserts the Content-Transfer-Encoding header for quoted-printable encoding into the third MIME part.
//14Constructs an RWMimeMultipartType for multipart/mixed content. The constructor automatically generates a boundary string.
//15Constructs an RWMimeMultipart with the multipart/mixed Content-Type created on line //14.
//16Each of the next three lines creates an email header for the MIME message. The headers are instances of RWMimeGenericHeader. The MIME package provides RWMimeGenericHeader for headers that are not part of the MIME specification.
//17Inserts a MIME-Version header into the part. A MIME message requires a MIME-Version header. A default-constructed RWMimeVersionHeader contains the correct version number.
//18Each of the next three lines inserts a header into the part.
//19Creates a preamble for the multipart message. Although the MIME specification doesn't require a multipart message to contain a preamble, most multipart messages provide one.
//20Converts the preamble to canonical form.
//21Sets the preamble of the multipart body.
//22Each of the next three lines inserts a MIME part into the multipart body.
//23Prints the message to standard output. A production application would typically enclose the asString() function in a try block, since the function throws an RWMimeError if it can't create a MIME string with the correct syntax. Since this example uses a constant string, we've left out the try block for clarity.

The exact output of the program varies since the automatically-generated boundary string includes a timestamp. Further, we've wrapped some of the longer lines. Taking those differences into account, the output of the program is similar to:



Previous fileTop of DocumentContentsIndex pageNext file

© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.