CMimeEncode

CMimeEncode - Implements a MIME encoding class for MFC.
This class is a simplified version of the Microsoft ATL MIME classes (CMimeMessage, CMimeHeader, CMimeAttachment etc) from Visual Studio 7. Most encoding functions are taken from these classes, but have been modfied to work with MFC and sometimes a little bit tweaked for easier usage.
CMimeEncode can be used together with CSmtpSocket to send MIME encoded email messages.


Methods:
These methods can be used to set and get the standard MIME header values:
void SetSender(LPCTSTR lpszFrom, LPCTSTR lpszDisplayName = NULL);
LPCSTR GetSender();

void SetSubject(LPCTSTR lpszSubject);
LPCSTR GetSubject();

void AddRecipient(LPCTSTR lpszAddress, LPCTSTR lpszName = NULL);
LPCSTR GetRecipients();

void AddCc(LPCTSTR lpszAddress, LPCTSTR lpszName = NULL);
LPCSTR GetCc();

void AddBcc(LPCTSTR lpszAddress);
LPCSTR GetBcc();

BOOL SetPriority(AFX_MIME_PRIORITY nPriority);
AFX_MIME_PRIORITY GetPriority();

where nPriority is one of these values:
AFX_MIME_HIGH_PRIORITY
AFX_MIME_NORMAL_PRIORITY
AFX_MIME_LOW_PRIORITY
AFX_MIME_PRIORITY_ERROR


You can add a usag define header with:
void AddUserDefinedHeader(LPCTSTR lpszHeaderName, LPCTSTR lpszHeader);


To add data to the message body use one of the following methods:
void AddText(LPCTSTR lpszText, LPCTSTR lpszContentType = "text/plain",
int nEncodingScheme = AFXSMTP_7BIT_ENCODE);
Add text to the message, using the specified content type and encoding scheme.

void AddRaw(BYTE *pbData, int nLength, LPCTSTR lpszDisplayName,
LPCTSTR lpszContentType, int nEncodingScheme = AFXSMTP_BASE64_ENCODE);

Add raw data to the message, using the specified content type and encoding scheme.

void AddFile(LPCTSTR lpszFileName, LPCTSTR lpszContentType = NULL, int nEncodingScheme = AFXSMTP_BASE64_ENCODE);

Add the content of a file to the message, using the specified content type and encoding scheme.

Supported Encoding schemes:
AFXSMTP_BASE64_ENCODE (base64)
AFXSMTP_UUENCODE
(uu encoded)
AFXSMTP_QP_ENCODE
(quoted-printable)
AFXSMTP_7BIT_ENCODE
(no encoding)


To render the message use:
BOOL RenderMessage(CString &strMessage);


Example:

CMimeEncode mimeEncode;

// Set the sender of the message
mimeEncode.SetSender("from@email.com");

// Add the recipient(s)
mimeEncode.AddRecipient("to@email.com", "Pablo Software Solutions");
mimeEncode.AddCc("billgates@email.com", "Bill Gates");

// Add the subject
mimeEncode.SetSubject("Put the subject here");

// Add the message text (body text)
mimeEncode.AddText("This message is plain text");

// Add files to the message
mimeEncode.AddFile("attachement.zip");

// Set the message priority
mimeEncode.SetPriority(AFX_MIME_NORMAL_PRIORITY);

CString strEncodedMsg;
mimeEncode.RenderMessage(strEncodedMsg);

// now we have an encoded message!


Download demo executable

Download source code
This class is part of the Pablo Software Solutions MFC Extension Package - Classes Edition

Also available:
CMimeDecode
CSmtpSocket
CPop3Socket
 

[Home] [Products] [Source Code] [Downloads] [Support]

© 2015 - Pablo Software Solutions
All rights reserved.