PrevNextUpHome BREW C++ Class Library & GUI Framework & XML Middleware : SophiaFramework 4.1
SFXMailMessage
Class for processing a mail message.
#include <SFXMailMessage.h.hpp>
class SFXMailMessage;
SFMTYPEDEFCLASS(SFXMailMessage)

Collaboration diagram

 Collaboration diagram of SFXMailMessageClass

Description

Class to process the mail message that is defined in RFC2822 (Internet Message Format). With this class you can create, change, write, and parse mail messages. Multi-part message and attached file can also be processed.

Procedure to send a SMTP mail.

  1. Create the instance of the SFXMailMessage class.
  2. Set the Subject field using the SFXMailMessage::SetSubjectField function.
  3. Set the From field using the SFXMailMessage::SetFromField function.
  4. Set To field using the SFXMailMessage::AddToField function. To set multiple addresses, call this function multiple times.
  5. If neccesary, use the SFXMailMessage::AddCcField and SFXMailMessage::AddBccField functions to set Cc filed and Bcc field.
  6. To set other fields, call the SFXMailMessage::AddField function.
  7. Set the Body using the SFXMailMessage::SetBody function.
  8. To process the attached files, use the SFXMailMessage::AttachFile function.
  9. Finally, create the mail message using the SFXMailMessage::Write function.

Example 476. Create a mail message

class MyClass {
private:
    SFXSMTPSender _sender;
    CALLBACK_DECLARE_SFXSMTPSENDER(SMTPCallback)
public:
    Void Start(Void);
};

Void MyClass::Start(Void)
{
    SFCError error;
    SFXMailMessage message;
    
    // set Subject field to mail header
    message.SetSubjectField("Mail Subject");

    // set From field to mail header
    message.SetFromField("fromaddress@example.com");

    // add To address to mail header
    message.AddToField("toaddress1@example.com");
    message.AddToField("toaddress2@example.com");
    
    // add Cc address to mail header
    message.AddCcField("toaddress3@example.com");
    
    // add Bcc address to mail header
    message.AddBccField("toaddress4@example.com");
    
    // add Content Type to mail header
    message.AddField("Content-Type", "text");

    // set Body of mail message
    message.SetBody("Mail test\r\nThis mail is sent by SFXSMTPSender.\r\n");
    
    // create file name to attach
    SFXBuffer buff("Hello", 5);        
    attach file to the mail message
    message.AttachFile(buff, "filename.txt", "text", "plain");

    // specify IP address and port number of SMTP server (domain is automatically resolved) 
    _sender.SetServer(SFXSocketAddress("smtpserver.example.com:25"));

    // register SMTPCallback as callback function, and then send mail
    // SMTPCallback function will be notified of completion of sending mail
    if ((error = _sender.SendMessage(&message,
        CALLBACK_FUNCTION(SMTPCallback))) != SFERR_NO_ERROR) {
        // callback will never be notifiled to SMTPCallback function if error is not SFERR_NO_ERROR
        // error handling for this case
    }
}

// callback function notified of completion of sending mail

CALLBACK_IMPLEMENT_SFXSMTPSENDER(MyClass, SMTPCallback, error)
{
    if (error == SFERR_NO_ERROR) {
        TRACE("Mail has been sent.");
    }
    else {
        TRACE("Mail sending failed. %d", error);
    }
}

Procedure to receive a POP3 mail

  1. Create the instance of the SFXMailMessage class.
  2. Parse the received mail message using the SFXMailMessage::Parse function.
  3. Get Subject field, From field, To field, Cc field, Bcc field, and Date field using the SFXMailMessage::GetSubjectField, SFXMailMessage::GetFromField, SFXMailMessage::GetToField, SFXMailMessage::GetCcField, SFXMailMessage::GetBccField, and SFXMailMessage::GetDateField functions respectively.
  4. Get the Body using the SFXMailMessage::GetBody or SFXMailMessage::GetBodyText function.
  5. Get the attached files using the SFXMailMessage::GetAttachedFile function.
[Note] Processing of a multi-part message

To process a multi-part message, use the SFXMailMessage::IsMultipart function.

Example 477. Parse the received mail message

// received mail message
SFXAnsiString receivedString =
    "From: Albert Einstein <einstein@example.com>\r\n"
    "To: Isaac Newton <newton@example.com>\r\n"
    "Subject: untitled\r\n"
    "Date: Sat, 08 Mar 2008 20:37:58 +0900\r\n"
    "\r\n"
    "This is a mail body.\r\n";

SFXMailMessage message;

// parse mail message
message.Parse(receivedString);

// get From field from mail header
// fromString: Albert Einstein <einstein@example.com>
SFXAnsiString fromString = message.GetFromField();

// get To field from mail header
// toString: Isaac Newton <newton@example.com>\r\n
SFXAnsiString toString = message.GetToField();

// get Subject field from mail header
// subjectString: untitled
SFXAnsiString subjectString = message.GetSubjectField();

// get Date field from mail header as instance of SFXDate class
SFXDate date = message.GetDateField();

// get Body
// bodyString: This is a mail body.\r\n
SFXAnsiString bodyString = message.GetBody();

Reference

SFXMailUtility | SFXMailField

Member

Constructor/Destructor
SFXMailMessage( Void )
Constructor of SFXMailMessage class.
~SFXMailMessage( Void )
Destructor of SFXMailMessage class.
Public Functions
SFCError AddBccField( SFXAnsiStringConstRef bcc )
Add the "bcc:" mail address to the Bcc field of the mail header.
SFCError AddCcField( SFXAnsiStringConstRef cc )
Add the "cc:" mail address to the Cc field of the mail header.
SFCError AddField( SFXAnsiStringConstRef name , SFXAnsiStringConstRef value )
Add a value to a field of the mail header.
SFCError AddMultipartBody( SFXMailMessagePtr body )
Add a message to the multi-part message.
SFCError AddToField( SFXAnsiStringConstRef to )
Add the "to:" mail address to the To field of the mail header.
SFCError AttachFile( SFXBufferConstRef file , SFXAnsiStringConstRef fileName , SFXAnsiStringConstRef mainType = "application" , SFXAnsiStringConstRef subType = "octet-stream" )
Attach a file to the mail message.
Void Clear( Void )
Clear the content of the mail message.
SFCError GetAttachedFile( SInt32 index , SFXBufferPtr data , SFXAnsiStringPtr fileName , SFXAnsiStringPtr mainType = null , SFXAnsiStringPtr subType = null )
Get the attached file.
SFXAnsiString GetBccField( Bool isDecoding = true )
Get the value of the Bcc field of the mail message.
SFXAnsiString GetBody( Bool isDecoding = true )
Get the body of the mail message.
SFXAnsiStringConstRef GetBodyRef( Void )
Get the body reference of the mail message.
SFXAnsiString GetBodyText( Bool isDecoding = true )
Get the body of the mail message.
SFXAnsiString GetCcField( Bool isDecoding = true )
Get the value of the Cc field of the mail message.
SFXAnsiString GetContentType( Void )
Get the value of the Content-Type of the mail message.
SFCError GetContentType( SFXAnsiStringPtr mainType , SFXAnsiStringPtr subType , SFXPropertyConstHandle attribute )
Get the value of the Content-Type of the mail message.
SFXDate GetDateField( Void )
Get the value of the Date field of the mail header.
SFXAnsiString GetEpilogue( Bool isDecoding = true )
Get the Epilogue (suffix part) of the multi-part message.
SFXAnsiString GetField( SFXAnsiStringConstRef name , Bool isDecoding = true , BoolPtr found = null )
Get the value of a specified field of the mail header.
SFXPropertyConstRef GetFieldList( Void )
Get all the header fields of the mail message.
SFXAnsiString GetFromField( Bool isDecoding = true )
Get the value of the From field of the mail message.
SFXMailMessagePtr GetMultipartMessage( SInt32 index )
Get a specified internal message in the multi-part message.
UInt32 GetMultipartSize( Void )
Get the number of the internal messages in the multi-part message.
SFXAnsiString GetPreamble( Bool isDecoding = true )
Get the Preamble(prefix part) of the multi-part message.
SFXAnsiString GetSubjectField( Bool isDecoding = true )
Get the value of the Subject field of the mail header.
SFXAnsiString GetToField( Bool isDecoding = true )
Get the value of the To field of the mail header.
Bool HasField( SFXAnsiStringConstRef name )
Check whether or not the mail header has a specified field.
Bool IsMultipart( Void )
Check whether this is a multi-part message or not.
SFCError Parse( ACharConstPtr message )
Parse( ACharConstPtr start , ACharConstPtr end )
Parse( SFXAnsiStringConstRef message )
Parse the text and read it as mail message.
SFCError ParseHeaderOnly( ACharConstPtr message )
ParseHeaderOnly( ACharConstPtr start , ACharConstPtr end )
ParseHeaderOnly( SFXAnsiStringConstRef message )
Parse the text, and only the header is read as mail message.
Void RemoveField( SFXAnsiStringConstRef name )
Remove the specified field from the mail header.
SFCError ReplaceBccField( SFXAnsiStringConstRef bcc )
Replace the Bcc field in the mail header with a specifdied "bcc:" mail address.
SFCError ReplaceCcField( SFXAnsiStringConstRef cc )
Replace Cc field in the mail header with a specifdied "cc:" mail address.
SFCError ReplaceField( SFXAnsiStringConstRef name , SFXAnsiStringConstRef value )
Replace the value of the specified field of the mail header with a specified value.
SFCError ReplaceToField( SFXAnsiStringConstRef to )
Replace the To field in the mail header with a specifdied "to:" mail address.
SFCError SetBody( SFXAnsiStringConstRef text )
Set the body of the mail message.
SFCError SetContentType( SFXAnsiStringConstRef mainType , SFXAnsiStringConstRef subType )
SetContentType( SFXAnsiStringConstRef mainType , SFXAnsiStringConstRef subType , SFXPropertyConstRef attribute )
Set the Content-Type of the mail message.
SFCError SetEpilogue( SFXAnsiStringConstRef text )
Set a specified text to the Epilogue(suffix part) of the multi-part message.
SFCError SetFromField( SFXAnsiStringConstRef from )
Set a specified "from" mail address to the From field of the mail header.
SFCError SetPreamble( SFXAnsiStringConstRef text )
Set a specified text to the Preamble(prefix part) of the mail message.
SFCError SetSubjectField( SFXAnsiStringConstRef subject )
Set a specified "subject" text to the Subject field of the mail header.
SFXAnsiString Write( Bool isEncoding = true , UInt32 fieldMaxLen = 78 )
Write the mail message as text.
Types
DocList
Prototype that represents a list of mail message.

SFXMailMessage::SFXMailMessage
Constructor of SFXMailMessage class.
[ public, explicit ]
SFXMailMessage(Void);

SFXMailMessage::~SFXMailMessage
Destructor of SFXMailMessage class.
[ public ]
~SFXMailMessage(Void);

Description

The SFXMailMessage class instance is destroyed. All sub-documents maintained internally are deleted.


SFXMailMessage::AddBccField
Add the "bcc:" mail address to the Bcc field of the mail header.
[ public ]
SFCError AddBccField(
    SFXAnsiStringConstRef bcc   // "bcc:" mail address
);

Argument

bcc

Specify the "bcc:" mail address.

Return value

  • Success : SFERR_NO_ERROR
  • If field value is invalid : SFERR_INVALID_PARAM
  • If format is invalid : SFERR_INVALID_FORMAT
  • If insufficient memory : SFERR_NO_MEMORY
  • If failed : SFERR_FAILED

Reference

SFXMailMessage::ReplaceField | SFXMailMessage::HasField | SFXMailMessage::GetField | SFXMailMessage::GetFieldList


SFXMailMessage::AddCcField
Add the "cc:" mail address to the Cc field of the mail header.
[ public ]
SFCError AddCcField(
    SFXAnsiStringConstRef cc   // "cc:" mail address
);

Argument

cc

Specify the "cc:" mail address.

Return value

  • Success : SFERR_NO_ERROR
  • If field value is invalid : SFERR_INVALID_PARAM
  • If format is invalid : SFERR_INVALID_FORMAT
  • If insufficient memory : SFERR_NO_MEMORY
  • If failed : SFERR_FAILED

Reference

SFXMailMessage::ReplaceField | SFXMailMessage::HasField | SFXMailMessage::GetField | SFXMailMessage::GetFieldList


SFXMailMessage::AddField
Add a value to a field of the mail header.
[ public ]
SFCError AddField(
    SFXAnsiStringConstRef name    // name of the field
    SFXAnsiStringConstRef value   // value of the field
);

Argument

name

Specify a valid string for the field name of the mail header.

value

Specify the value of the field.

Return value

  • Success : SFERR_NO_ERROR
  • Invalid file name or data : SFERR_INVALID_PARAM
  • If format is invalid : SFERR_INVALID_FORMAT
  • If insufficient memory : SFERR_NO_MEMORY
  • If failed : SFERR_FAILED

Description

Different from the SFXMailMessage::ReplaceField function, the SFXMailMessage::AddField function adds the value without deleting the existing values of the field.

For the fields such as From, To, etc. that can not have more than one value, use the SFXMailMessage::ReplaceField function to replace the existing value. For the fields such as Received that can have more than one value, use the SFXMailMessage::AddField function to add the value.

Reference

SFXMailMessage::ReplaceField | SFXMailMessage::HasField | SFXMailMessage::GetField | SFXMailMessage::GetFieldList


SFXMailMessage::AddMultipartBody
Add a message to the multi-part message.
[ public ]
SFCError AddMultipartBody(
    SFXMailMessagePtr body   // message to be added
);

Argument

body

Specify the message to be added.

Return value

  • Success : SFERR_NO_ERROR
  • If Content-Type is not "multipart" : SFERR_INVALID_STATE
  • If insufficient memory : SFERR_NO_MEMORY
  • If failed : SFERR_FAILED

Description

Set "multipart" to the Content-Type using SFXMailMessage::SetContentType function before calling the SFXMailMessage::AddMultipartBody function.

Reference

SFXMailMessage::AttachFile | SFXMailMessage::SetContentType | SFXMailMessage::IsMultipart


SFXMailMessage::AddToField
Add the "to:" mail address to the To field of the mail header.
[ public ]
SFCError AddToField(
    SFXAnsiStringConstRef to   // "to:" mail address
);

Argument

to

Specify the "to:" mail address.

Return value

  • Success : SFERR_NO_ERROR
  • If field value is invalid : SFERR_INVALID_PARAM
  • If format is invalid : SFERR_INVALID_FORMAT
  • If insufficient memory : SFERR_NO_MEMORY
  • If failed : SFERR_FAILED

Reference

SFXMailMessage::ReplaceField | SFXMailMessage::HasField | SFXMailMessage::GetField | SFXMailMessage::GetFieldList


SFXMailMessage::AttachFile
Attach a file to the mail message.
[ public ]
SFCError AttachFile(
    SFXBufferConstRef file                           // attached data
    SFXAnsiStringConstRef fileName                   // name of attached file
    SFXAnsiStringConstRef mainType = "application"   // Content-Type of attached data
    SFXAnsiStringConstRef subType = "octet-stream"   // Content-Sub-Type of attached data
);

Argument

file

Specify the data to be attached. (Any data can be attached.)

fileName

Specify the file name to be attached.

[Note] Note
If "null" is specified, data will be not attached but inlined.
mainType

Specify the Content-Type of data to be attached.

Specify "text" if text and "image" if image.

[Note] Note
If this argument is not specified, "application" is set by default.
subType

Specify the Content-Sub-Type of data to be attached.

In case of the Jpeg image, "image" and "jpeg" need to be set to the "mainType" and "subType" arguments respectively.

[Note] Note
If this argument is not specified, "octet-stream" is set by default.

Return value

  • Success : SFERR_NO_ERROR
  • If name of attached file is invalid : SFERR_INVALID_PARAM
  • If Content-Type is invalid : SFERR_INVALID_STATE
  • If format is invalid : SFERR_INVALID_FORMAT
  • If insufficient memory : SFERR_NO_MEMORY
  • If failed : SFERR_FAILED

Description

The mail body should be set by the SFXMailMessage::SetBody before the SFXMailMessage::AttachFile function is called. At the time when the SFXMailMessage::AttatchFile function is called, the mail message comes to have the multi-part part even if the original message has no multi-part.

Attached data will be automatically encoded in the Base64 format.

The internal procedure to attach a file to the mail message is as follows.

  1. Set a specified string to the Content-Type of the header of attached data, Base64 to the Content-Transfer-Encoding, and "inline" or "attachment" to the Content-Disposition with its filename as file attribute.
  2. Attached data is encoded in the Base64 format.
  3. If the original message has no multi-part, the Content-Type will be changed into "multipart/mixed", and the current body text will be the first message of the multi-part message(Content-Type is "text/plain").
  4. Attached data is added as a multi-part body of the multi-part message.

Example

Attach a text file.

// attach to SFXMailMessage msg
msg.SetBody("Message Body");    // set Body before attaching file
SFXBuffer buff1("abc", 3);        // text file to be attached (file 1)
SFXBuffer buff2("defghij", 7);    // text file to be attached (file 2)
msg.AttachFile(buff1, "filename1.txt", "text", "plain");
msg.AttachFile(buff2, "filename2.txt", "text", "plain");

Reference

SFXMailMessage::AddMultipartBody | SFXMailMessage::IsMultipart


SFXMailMessage::Clear
Clear the content of the mail message.
[ public ]
Void Clear(Void);

SFXMailMessage::GetAttachedFile
Get the attached file.
[ public, const ]
SFCError GetAttachedFile(
    SInt32 index                       // file number
    SFXBufferPtr data                  // attached data
    SFXAnsiStringPtr fileName          // name of attached file
    SFXAnsiStringPtr mainType = null   // Content-Type of attached data
    SFXAnsiStringPtr subType = null    // Content-Sub-Type of attached data
);

Argument

index

Specify the index of the file to be taken.

The number of attached files can be obtained by the SFXMailMessage::GetMultipartSize function. The "index" number starts from 0.

data

Specify the destination to store the attached data. If not necessary, specify "null".

fileName

Specify the destination to store the file name of attached data. If not necessary, specify "null".

mainType

Specify the destination to store the Content-Type of attached data. If not necessary, specify "null".

subType

Specify the destination to store the Content-Sub-Type of attached data. If not necessary, specify "null".

Return value

  • Success : SFERR_NO_ERROR
  • If format is invalid : SFERR_INVALID_FORMAT
  • If index is out of range : SFERR_INVALID_PARAM
  • If insufficient memory : SFERR_NO_MEMORY
  • If message does not have the multi-part part : SFERR_FAILED

Description

The file encoded in the Base64 format is automaticaly decoded.

Reference

SFXMailMessage::AddMultipartBody | SFXMailMessage::IsMultipart | SFXMailMessage::AttachFile | SFXMailMessage::GetMultipartSize


SFXMailMessage::GetBccField
Get the value of the Bcc field of the mail message.
[ public, const ]
SFXAnsiString GetBccField(
    Bool isDecoding = true   // whether or not to decode
);

Argument

isDecoding

Specify whether or not to decode.

If true: The mail message encoded in the Quoted-Printable or Base64 format will be decoded. The mail message in Japanese will be converted into the Shift-JIS code.

Default: true.

Return value

Return the value of the Bcc field.

Reference

SFXMailMessage::AddField | SFXMailMessage::ReplaceField | SFXMailMessage::GetFieldList | SFXMailMessage::HasField


SFXMailMessage::GetBody
Get the body of the mail message.
[ public, const ]
SFXAnsiString GetBody(
    Bool isDecoding = true   // decode or not?
);

Argument

isDecoding

Specify whether or not to decode.

If true: The mail message encoded in the Quoted-Printable or Base64 format will be decoded. The mail message in Japanese will be converted into the Shift-JIS code.

Default: true.

Return value

Return the body of the mail message.

Return null in case of the multi-part message.

Description

To get the body of multi-part message, use the SFXMailMessage::GetMultipartMessage function.

Reference

SFXMailMessage::SetBody | SFXMailMessage::GetMultipartMessage | SFXMailMessage::GetBodyText


SFXMailMessage::GetBodyRef
Get the body reference of the mail message.
[ public, const ]
SFXAnsiStringConstRef GetBodyRef(Void);

Return value

Return the reference to the body of the mail message.

Return a reference to the "null" string in case of the multi-part message.

Description

To deal with the body of the mail message efficiently, use the SFXMailMessage::GetBodyRef function.

Reference

SFXMailMessage::SetBody | SFXMailMessage::GetBody | SFXMailMessage::GetBodyText


SFXMailMessage::GetBodyText
Get the body of the mail message.
[ public, const ]
SFXAnsiString GetBodyText(
    Bool isDecoding = true   // whether or not to decode
);

Argument

isDecoding

Specify whether or not to decode.

If true: The mail message encoded in the Quoted-Printable or Base64 format will be decoded. The mail message in Japanese will be converted into the Shift-JIS code.

Default: true.

Return value

Return the body of the mail message.

In case of the multi-part message, the first text of the multi-part part is returned.

Reference

SFXMailMessage::SetBody | SFXMailMessage::GetMultipartMessage | SFXMailMessage::GetBody


SFXMailMessage::GetCcField
Get the value of the Cc field of the mail message.
[ public, const ]
SFXAnsiString GetCcField(
    Bool isDecoding = true   // whether or not to decode
);

Argument

isDecoding

Specify whether or not to decode.

If true: The mail message encoded in the Quoted-Printable or Base64 format will be decoded. The mail message in Japanese will be converted into the Shift-JIS code.

Default: true.

Return value

Return the value of the Cc field.

Reference

SFXMailMessage::AddField | SFXMailMessage::ReplaceField | SFXMailMessage::GetFieldList | SFXMailMessage::HasField


SFXMailMessage::GetContentType
Get the value of the Content-Type of the mail message.
[ public, const ]
SFXAnsiString GetContentType(Void);
[ public, const ]
SFCError GetContentType(
    SFXAnsiStringPtr mainType          // Content-Type
    SFXAnsiStringPtr subType           // Content-Sub-Type
    SFXPropertyConstHandle attribute   // attribute
);

Return value

  • Success : SFERR_NO_ERROR
  • If insufficient memory : SFERR_NO_MEMORY

Reference

SFXMailMessage::SetContentType


SFXMailMessage::GetDateField
Get the value of the Date field of the mail header.
[ public, const ]
SFXDate GetDateField(Void);

Return value

Return the value of the Date field in the SFXDate format.

Reference

SFXMailMessage::AddField | SFXMailMessage::ReplaceField | SFXMailMessage::GetFieldList | SFXMailMessage::HasField


SFXMailMessage::GetEpilogue
Get the Epilogue (suffix part) of the multi-part message.
[ public, const ]
SFXAnsiString GetEpilogue(
    Bool isDecoding = true   // whether or not to decode
);

Argument

isDecoding

Specify whether or not to decode.

If true: The mail message encoded in the Quoted-Printable or Base64 format will be decoded. The mail message in Japanese will be converted into the Shift-JIS code.

Default: true.

Return value

Return the Epilogue (suffix part) of the multi-part message.

Return null if there is no Epilogue (suffix part) in the multi-part message.

Description

Epilogue (suffix part) is a string added at the end of the multi-part message defined in RFC2046 (MIME Part Two : Media Types Text).

Reference

SFXMailMessage::SetEpilogue | SFXMailMessage::GetPreamble | SFXMailMessage::SetPreamble | SFXMailMessage::IsMultipart


SFXMailMessage::GetField
Get the value of a specified field of the mail header.
[ public, const ]
SFXAnsiString GetField(
    SFXAnsiStringConstRef name   // field name
    Bool isDecoding = true       // whether or not to decode
    BoolPtr found = null         // whether the field exists or not
);

Argument

name

Specify a valid string for the field name of the mail header.

isDecoding

Specify whether or not to decode.

If true: The mail message encoded in the Quoted-Printable or Base64 format will be decoded. The mail message in Japanese will be converted into the Shift-JIS code.

Default: true.

found

Specify a pointer to the variable, where "true" will be returned if a specified field exists. Specify null if unnecessary.

Return value

Return the value of a specified field.

Description

If more than one value are stored with the same field name, only the first value is read.

To get all the values stored with the same field name, use the SFXMailMessage::GetFieldList function.

Reference

SFXMailMessage::AddField | SFXMailMessage::ReplaceField | SFXMailMessage::GetFieldList | SFXMailMessage::HasField


SFXMailMessage::GetFieldList
Get all the header fields of the mail message.
[ public, const ]
SFXPropertyConstRef GetFieldList(Void);

Return value

Return all the header fields of the mail message as the instance of the SFXProperty class.

Description

[Caution] Please edit the header of the mail message carefully!

The validity of the field names will not be checked when editing the header of the mail message using the SFXProperty instance obtained by the SFXMailMessage::GetFieldList function.

Therefore, you need to note the following items.

  • Only the alphabets and hyphen can be used for the field name.
  • The field name is case-insensitive, not case-sensitive.

Reference

SFXMailMessage::AddField | SFXMailMessage::ReplaceField | SFXMailMessage::GetField | SFXMailMessage::HasField | SFXProperty


SFXMailMessage::GetFromField
Get the value of the From field of the mail message.
[ public, const ]
SFXAnsiString GetFromField(
    Bool isDecoding = true   // whether or not to decode
);

Argument

isDecoding

Specify whether or not to decode.

If true: The mail message encoded in the Quoted-Printable or Base64 format will be decoded. The mail message in Japanese will be converted into the Shift-JIS code.

Default: true.

Return value

Return From field value.

Reference

SFXMailMessage::AddField | SFXMailMessage::ReplaceField | SFXMailMessage::GetFieldList | SFXMailMessage::HasField


SFXMailMessage::GetMultipartMessage
Get a specified internal message in the multi-part message.
[ public ]
SFXMailMessagePtr GetMultipartMessage(
    SInt32 index   // internal message index
);

Return value

Return a pointer to the internal message in the multi-part message(instance of the SFXMailMessage class).

Description

The multi-part message has multiple internal messages as instances of SFXMailMessage class.

The pointer to any internal message can be obtained by specifying its "index" number(The "index" number starts from 0).

If the mail message is not a multi-part message, or the "index" number is out of range, "null" is returned.

Example

Get the internal messages in the multi-part message one by one.

// "msg" has mail message
SInt32 i;
SFXMailMessage msg;
SFXMailMessagePtr mail;

if (msg.IsMultipart()) { //check whether or not the mail message is multi-part
    for (i = 0; i < msg.GetMultipartSize(); i++) {
        mail = msg.GetMultipartMessage(i);
        // process mail
        ...
    }
}

Reference

SFXMailMessage::IsMultipart | SFXMailMessage::AddMultipartBody | SFXMailMessage::GetMultipartMessage


SFXMailMessage::GetMultipartSize
Get the number of the internal messages in the multi-part message.
[ public, const ]
UInt32 GetMultipartSize(Void);

Return value

Return the number of the internal messages in the multi-part message.

Return 0 if the message has no multi-part.

Reference

SFXMailMessage::GetMultipartMessage | SFXMailMessage::GetAttachedFile


SFXMailMessage::GetPreamble
Get the Preamble(prefix part) of the multi-part message.
[ public, const ]
SFXAnsiString GetPreamble(
    Bool isDecoding = true   // whether or not to decode
);

Argument

isDecoding

Specify whether or not to decode.

If true: The mail message encoded in the Quoted-Printable or Base64 format will be decoded. The mail message in Japanese will be converted into the Shift-JIS code.

Default: true.

Return value

Return the Preamble (prefix part) of the multi-part message.

Return null if there is no Preamble (prefix part) in the multi-part message.

Description

The Preamble(prefix part) is a string added at the beginning of the multi-part message defined in RFC2046 ( MIME Part Two : Media Types Text ).

The string such as "This is a MIME multipart message." is set.

Reference

SFXMailMessage::SetPreamble | SFXMailMessage::GetEpilogue | SFXMailMessage::SetEpilogue | SFXMailMessage::IsMultipart


SFXMailMessage::GetSubjectField
Get the value of the Subject field of the mail header.
[ public, const ]
SFXAnsiString GetSubjectField(
    Bool isDecoding = true   // whether or not to decode
);

Argument

isDecoding

Specify whether or not to decode.

If true: The mail message encoded in the Quoted-Printable or Base64 format will be decoded. The mail message in Japanese will be converted into the Shift-JIS code.

Default: true.

Return value

Return the value of the Subject field.

Reference

SFXMailMessage::AddField | SFXMailMessage::ReplaceField | SFXMailMessage::GetFieldList | SFXMailMessage::HasField


SFXMailMessage::GetToField
Get the value of the To field of the mail header.
[ public, const ]
SFXAnsiString GetToField(
    Bool isDecoding = true   // whether or not to decode
);

Argument

isDecoding

Specify whether or not to decode.

If true: The mail message encoded in the Quoted-Printable or Base64 format will be decoded. The mail message in Japanese will be converted into the Shift-JIS code.

Default: true.

Return value

Return the value of the To field.

Reference

SFXMailMessage::AddField | SFXMailMessage::ReplaceField | SFXMailMessage::GetFieldList | SFXMailMessage::HasField


SFXMailMessage::HasField
Check whether or not the mail header has a specified field.
[ public, const ]
Bool HasField(
    SFXAnsiStringConstRef name   // field name
);

Argument

name

Specify a valid string for the field name of the mail header.

Return value

  • If yes : true
  • Otherwise : false

Reference

SFXMailMessage::AddField | SFXMailMessage::ReplaceField | SFXMailMessage::GetField | SFXMailMessage::GetFieldList


SFXMailMessage::IsMultipart
Check whether this is a multi-part message or not.
[ public, const ]
Bool IsMultipart(Void);

Return value

  • If yes : true
  • Otherwise : false

Description

If the mainType of the Content-Type is "multipart", it is a multi-part message.

Reference

SFXMailMessage::SetContentType


SFXMailMessage::Parse
Parse the text and read it as mail message.
[ public ]
SFCError Parse(
    ACharConstPtr message   // text to be parsed
);
[ public ]
SFCError Parse(
    SFXAnsiStringConstRef message   // text to be parsed
);
[ public ]
SFCError Parse(
    ACharConstPtr start   // pointer to the beginning of text to be parsed
    ACharConstPtr end     // pointer to the end of text to be parsed
);

Argument

message

Text to be parsed as mail message.

start

Pointer to the beginnig of text to be parsed as mail message.

end

Pointer to the end of text to be parsed as mail message.

Return value

  • Success : SFERR_NO_ERROR
  • If text to be parsed is invalid : SFERR_INVALID_PARAM
  • If format is invalid : SFERR_INVALID_FORMAT
  • If insufficient memory : SFERR_NO_MEMORY

Description

The SFXMailMessage::Parse function can be used for the multi-part message.

Reference

SFXMailMessage::Write | SFXMailMessage::ParseHeaderOnly


SFXMailMessage::ParseHeaderOnly
Parse the text, and only the header is read as mail message.
[ public ]
SFCError ParseHeaderOnly(
    ACharConstPtr message   // text to be parsed
);
[ public ]
SFCError ParseHeaderOnly(
    SFXAnsiStringConstRef message   // text to be parsed
);
[ public ]
SFCError ParseHeaderOnly(
    ACharConstPtr start   // pointer to the beginning of the text to be parsed
    ACharConstPtr end     // pointer to the end of the text to be parsed
);

Argument

message

Text to be parsed as mail message.

start

Pointer to the beginning of the text to be parsed as mail message.

end

Pointer to the end of the text to be parsed as mail message.

Return value

  • Success : SFERR_NO_ERROR
  • If text to be parsed is invalid : SFERR_INVALID_PARAM
  • If format is invalid : SFERR_INVALID_FORMAT
  • If insufficient memory : SFERR_NO_MEMORY

Reference

SFXMailMessage::Write | SFXMailMessage::Parse


SFXMailMessage::RemoveField
Remove the specified field from the mail header.
[ public ]
Void RemoveField(
    SFXAnsiStringConstRef name   // name of field to be delete
);

Description

The SFXMailMessage::RemoveField function does nothing if the specified field does not exist.


SFXMailMessage::ReplaceBccField
Replace the Bcc field in the mail header with a specifdied "bcc:" mail address.
[ public ]
SFCError ReplaceBccField(
    SFXAnsiStringConstRef bcc   // "bcc:" mail address
);

Argument

bcc

Specify the value of the Bcc field to replace with.

Return value

  • Success : SFERR_NO_ERROR
  • If field value is invalid : SFERR_INVALID_PARAM
  • If format is invalid : SFERR_INVALID_FORMAT
  • If insufficient memory : SFERR_NO_MEMORY
  • If failed : SFERR_FAILED

Reference

SFXMailMessage::ReplaceField | SFXMailMessage::HasField | SFXMailMessage::GetField | SFXMailMessage::GetFieldList


SFXMailMessage::ReplaceCcField
Replace Cc field in the mail header with a specifdied "cc:" mail address.
[ public ]
SFCError ReplaceCcField(
    SFXAnsiStringConstRef cc   // "cc:" mail address
);

Argument

cc

Specify the value of the Cc field to replace with.

Return value

  • Success : SFERR_NO_ERROR
  • If field value is invalid : SFERR_INVALID_PARAM
  • If format is invalid : SFERR_INVALID_FORMAT
  • If insufficient memory : SFERR_NO_MEMORY
  • If failed : SFERR_FAILED

Reference

SFXMailMessage::ReplaceField | SFXMailMessage::HasField | SFXMailMessage::GetField | SFXMailMessage::GetFieldList


SFXMailMessage::ReplaceField
Replace the value of the specified field of the mail header with a specified value.
[ public ]
SFCError ReplaceField(
    SFXAnsiStringConstRef name    // field name
    SFXAnsiStringConstRef value   // value of field to replace with
);

Argument

name

Specify a valid string for the field name of the mail header.

value

Specify replaced data.

Return value

  • Success : SFERR_NO_ERROR
  • If field value is invalid : SFERR_INVALID_PARAM
  • If format is invalid : SFERR_INVALID_FORMAT
  • If insufficient memory : SFERR_NO_MEMORY
  • If failed : SFERR_FAILED

Description

If the specified field does not exist, it will be created with a specified value.

If the number of fields with a specified name is one, its value will be replaced with a specified value.

If the number of fields with a specified name is more than one, only the value of the first field will be replaced with a specified value.

Reference

SFXMailMessage::HasField | SFXMailMessage::AddField | SFXMailMessage::GetField | SFXMailMessage::GetFieldList


SFXMailMessage::ReplaceToField
Replace the To field in the mail header with a specifdied "to:" mail address.
[ public ]
SFCError ReplaceToField(
    SFXAnsiStringConstRef to   // "to:" mail address
);

Argument

to

Specify the value of the To field to replace with.

Return value

  • Success : SFERR_NO_ERROR
  • If field value is invalid : SFERR_INVALID_PARAM
  • If format is invalid : SFERR_INVALID_FORMAT
  • If insufficient memory : SFERR_NO_MEMORY
  • If failed : SFERR_FAILED

Reference

SFXMailMessage::ReplaceField | SFXMailMessage::HasField | SFXMailMessage::GetField | SFXMailMessage::GetFieldList


SFXMailMessage::SetBody
Set the body of the mail message.
[ public ]
SFCError SetBody(
    SFXAnsiStringConstRef text   // body of the mail message
);

Argument

text

Body of the mail message.

Return value

  • Success : SFERR_NO_ERROR
  • If message has no multi-part : SFERR_INVALID_STATE
  • If insufficient memory : SFERR_NO_MEMORY

Description

[Caution] Multi-part message

The SFXMailMessage::SetBody function fails in case of the multi-part message.

To add the Body to the multi-part message, create a instance of the SFXMailMessage class, set the Body to this instance, and add this instance to the multi-part message using the SFXMailMessage::AddMultipartBody function.

Reference

SFXMailMessage::GetBody | SFXMailMessage::AddMultipartBody | SFXMailMessage::IsMultipart


SFXMailMessage::SetContentType
Set the Content-Type of the mail message.
[ public ]
SFCError SetContentType(
    SFXAnsiStringConstRef mainType   // main type
    SFXAnsiStringConstRef subType    // subtype
);
[ public ]
SFCError SetContentType(
    SFXAnsiStringConstRef mainType   // Content-Type
    SFXAnsiStringConstRef subType    // Content-Sub-Type
    SFXPropertyConstRef attribute    // attribute
);

Return value

  • Success : SFERR_NO_ERROR
  • If invalid argumnet : SFERR_INVALID_PARAM
  • If insufficient memory : SFERR_NO_MEMORY
  • If failed : SFERR_FAILED

Description

If mainType is "multipart", the mail message is processed as a multi-part message.

Reference

SFXMailMessage::GetContentType | SFXMailMessage::IsMultipart


SFXMailMessage::SetEpilogue
Set a specified text to the Epilogue(suffix part) of the multi-part message.
[ public ]
SFCError SetEpilogue(
    SFXAnsiStringConstRef text   // Epilogue(suffix part)
);

Return value

  • Success : SFERR_NO_ERROR
  • If insufficient memory : SFERR_NO_MEMORY

Description

Epilogue(suffix part) is a string added at the end of the multi-part message defined in RFC2046 (MIME Part Two : Media Types Text).

This setting is invalid if the message has no multi-part.

Reference

SFXMailMessage::GetEpilogue | SFXMailMessage::GetPreamble | SFXMailMessage::SetPreamble | SFXMailMessage::IsMultipart


SFXMailMessage::SetFromField
Set a specified "from" mail address to the From field of the mail header.
[ public ]
SFCError SetFromField(
    SFXAnsiStringConstRef from   // "from" mail address
);

Argument

from

Specify the value of the From field.

Return value

  • Success : SFERR_NO_ERROR
  • If field value is invalid : SFERR_INVALID_PARAM
  • If format is invalid : SFERR_INVALID_FORMAT
  • If insufficient memory : SFERR_NO_MEMORY
  • If failed : SFERR_FAILED

Reference

SFXMailMessage::ReplaceField | SFXMailMessage::HasField | SFXMailMessage::GetField | SFXMailMessage::GetFieldList


SFXMailMessage::SetPreamble
Set a specified text to the Preamble(prefix part) of the mail message.
[ public ]
SFCError SetPreamble(
    SFXAnsiStringConstRef text   // Preamble(prefix part)
);

Return value

  • Success : SFERR_NO_ERROR
  • If insufficient memory : SFERR_NO_MEMORY

Description

Preamble (prefix part) is a string added at the beginning of the multi-part message defined in RFC2046 (MIME Part Two : Media Types Text).

A string such as "This is a MIME multi-part message." is set.

This setting is invalid if the message has no multi-part.

Reference

SFXMailMessage::GetPreamble | SFXMailMessage::GetEpilogue | SFXMailMessage::SetEpilogue | SFXMailMessage::IsMultipart


SFXMailMessage::SetSubjectField
Set a specified "subject" text to the Subject field of the mail header.
[ public ]
SFCError SetSubjectField(
    SFXAnsiStringConstRef subject   // "subject" text
);

Argument

subject

Specify the value of the Subject field.

Return value

  • Success : SFERR_NO_ERROR
  • If invalid subject : SFERR_INVALID_PARAM
  • If format is invalid : SFERR_INVALID_FORMAT
  • If insufficient memory : SFERR_NO_MEMORY
  • If failed : SFERR_FAILED

Reference

SFXMailMessage::ReplaceField | SFXMailMessage::HasField | SFXMailMessage::GetField | SFXMailMessage::GetFieldList


SFXMailMessage::Write
Write the mail message as text.
[ public ]
SFXAnsiString Write(
    Bool isEncoding = true    // whether or not to encode
    UInt32 fieldMaxLen = 78   // loopback digits of header
);

Argument

isEncoding

Specify whether or not to encode.

If true: the header encoded in Shift-JIS code will be encoded in Base64 and written. The body of the mail message is encoded in the JIS code(ISO-2022-JP).

Default: true.

fieldMaxLen

Specify the loopback digits(excluding CR and LF) of the header.

The characters in the header line at greater digit than the fieldMaxLen argument is automatically turned back. The value of the fieldMaxLen argument needs to be specified between 4 and 998.

Return value

Return the mail message as text.

Description

The mail message is written as text. If "true" is set to the isEncode argument, it is automatically converted into a appropriate character-code for sending mail.

Reference

SFXMailMessage::Parse


SFXMailMessage::DocList
Prototype that represents a list of mail message.
typedef SFXArray<SFXMailMessagePtr> DocList