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


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 27: Creating a simple MIME message

//1First, 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.
//2Creates an RWMimeTextType for the value "text/plain". This is the content type of an email message.
//3Constructs an RWCString containing the body of the message. Notice that the line breaks in the message text are newline (LF) characters.
//4Converts 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.
//5Creates an RWMimePart. The constructor adds a Content-Type header with the value textType.
//6Creates an MIME-Version header and adds the header to the message.
//7Inserts the "To:" header into the message. The next few lines add the other email headers to the message.
//8Adds the message body to the message.
//9Prints 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 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.