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 29 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.


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 29: Creating a multipart MIME message

//1

Creates an RWMimeTextType for the value "text/plain".

//2

Constructs a Content-Transfer-Encoding header for base 64 encoding.

//3

Constructs a Content-Transfer-Encoding header for quoted-printable encoding.

//4

Constructs the string that forms the basic content for each part of the multipart message.

//5

Converts the content string to canonical form.

//6

Encodes the content string using base 64 encoding and stores the result in a new string.

//7

Encodes the content string using quoted-printable encoding and stores the result in a new string.

//8

Constructs three new RWMimePart objects. Each object has a Content-Type header with the value textType.

//9

Sets the body of the first MIME part to the unencoded content.

//10

Inserts the Content-Transfer-Encoding header for base 64 encoding into the second MIME part.

//11

Sets the body of the second MIME part to the base 64 encoded content.

//12

Inserts the Content-Type header for text/plain into the third MIME part.

//13

Inserts the Content-Transfer-Encoding header for quoted-printable encoding into the third MIME part.

//14

Constructs an RWMimeMultipartType for multipart/mixed content. The constructor automatically generates a boundary string.

//15

Constructs an RWMimeMultipart with the multipart/mixed C-ontent-Type created on line //14.

//16

Each 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.

//17

Inserts a MIME-Version header into the part. A MIME message requires a MIME-Version header. A default-constructed RWMimeVersionHeader contains the correct version number.

//18

Each of the next three lines inserts a header into the part.

//19

Creates 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.

//20

Converts the preamble to canonical form.

//21

Sets the preamble of the multipart body.

//22

Each of the next three lines inserts a MIME part into the multipart body.

//23

Prints 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.

The Rogue Wave name and logo, and SourcePro, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.