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.3 Program: Creating a Simple MIME Message

Example 28 uses the MIME package to generate a simple MIME email message. The source code for this program is located in the file BasicMimeMessageComposition.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 28: Creating a simple MIME message

//1

First, the application generates headers for the email message. This line creates the "To:" header required for an Internet email message. Since RWMimeGenericHeader meets the requirements for an RFC 2822 header, we use instances of RWMimeGenericHeader for the email headers in the message. The next two lines of code create the "From:" and "Subject:" headers needed for an email message.

//2

Creates an RWMimeTextType for the value "text/plain". This is the content type of an email message.

//3

Constructs an RWCString containing the body of the message. Notice that the line breaks in the message text are newline (LF) characters.

//4

Converts the message to canonical form. Since the body is already in 7-bit ASCII text with lines that are less than 78 characters, there's no need to encode the message.

//5

Creates an RWMimePart. The constructor adds a Content-Type header with the value textType.

//6

Creates an MIME-Version header and adds the header to the message.

//7

Inserts the "To:" header into the message. The next few lines add the other email headers to the message.

//8

Adds the message body to the message.

//9

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 program produces the following output:



Previous fileTop of DocumentContentsNo linkNext 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.
Provide feedback to Rogue Wave about its documentation.