PrevNextUpHome SophiaFramework UNIVERSE 5.3
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.

[Caution] Encoding of the Subject field and the file name of attached data

RFC2231(MIME Parameter Value and Encoded Word Extensions) is not supported.

Procedure to send a SMTP mail.

  1. Create the SFXMailMessage instance.
  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 824. Create a mail message

class MyClass {
private:
    SFXSMTPSender _sender;
    XALLBACK_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 the completion of sending mail
    if ((error = _sender.SendMessage(&message,
        XALLBACK_INTERNAL(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 the completion of sending mail

XALLBACK_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 SFXMailMessage instance.
  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 825. 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>"
SFXAnsiString toString = message.GetToField();

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

// get Date field from mail header as SFXDate instance
// date: "Sat, 08 Mar 2008 20:37:58 +0900"
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 the SFXMailMessage class.
~SFXMailMessage( Void )
Destructor of the 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 this mail message.
SFCError GetAttachedFile( SInt32 index , SFXBufferPtr data , SFXAnsiStringPtr fileName , SFXAnsiStringPtr mainType = null , SFXAnsiStringPtr subType = null )
Get the attached file of this mail message.
SFXAnsiString GetBccField( Bool isDecoding = true )
Get the value of the Bcc field of this mail message.
SFXAnsiString GetBody( Bool isDecoding = true )
Get the body of this mail message.
SFXAnsiStringConstRef GetBodyRef( Void )
Get the body reference of this mail message.
SFXAnsiString GetBodyText( Bool isDecoding = true )
Get the body of this mail message.
SFXAnsiString GetCcField( Bool isDecoding = true )
Get the value of the Cc field of this mail message.
SFXAnsiString GetContentType( Void )
Get the value of Content-Type of this mail message.
SFCError GetContentType( SFXAnsiStringPtr mainType , SFXAnsiStringPtr subType , SFXPropertyConstHandle attribute )
Get the value of Content-Type of this mail message.
SFXDate GetDateField( Void )
Get the value of the Date field of the mail header of this mail message.
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 the specified field of the mail header of this mail message.
SFXPropertyConstRef GetFieldList( Void )
Get all the header fields of this mail message.
SFXAnsiString GetFromField( Bool isDecoding = true )
Get the value of the From field of this mail message.
SFXMailMessagePtr GetMultipartMessage( SInt32 index )
Get the specified internal message in the multi-part message.
UInt32 GetMultipartSize( Void )
Get the number of 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 of this mail message.
SFXAnsiString GetToField( Bool isDecoding = true )
Get the value of the To field of the mail header of this mail message.
Bool HasField( SFXAnsiStringConstRef name )
Check whether or not the mail header has the specified field.
Bool IsMultipart( Void )
Check whether or not this is a multi-part message.
SFCError Parse( ACharConstPtr message )
Parse the specified text and read it as a mail message.
SFCError Parse( SFXAnsiStringConstRef message )
Parse the specified text and read it as a mail message.
SFCError Parse( ACharConstPtr start , ACharConstPtr end )
Parse the specified text and read it as a mail message.
SFCError ParseHeaderOnly( ACharConstPtr message )
Parse the specified text, and only the header is read as a mail message.
SFCError ParseHeaderOnly( SFXAnsiStringConstRef message )
Parse the specified text, and only the header is read as a mail message.
SFCError ParseHeaderOnly( ACharConstPtr start , ACharConstPtr end )
Parse the specified text, and only the header is read as a mail message.
Void RemoveField( SFXAnsiStringConstRef name )
Remove the specified field from the mail header.
SFCError ReplaceBccField( SFXAnsiStringConstRef bcc )
Replace the Bcc field of the mail header with a specifdied "bcc:" mail address.
SFCError ReplaceCcField( SFXAnsiStringConstRef cc )
Replace the Cc field of 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 the 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 this mail message.
SFCError SetContentType( SFXAnsiStringConstRef mainType , SFXAnsiStringConstRef subType )
Set the Content-Type of this mail message.
SFCError SetContentType( SFXAnsiStringConstRef mainType , SFXAnsiStringConstRef subType , SFXPropertyConstRef attribute )
Set the Content-Type of this mail message.
SFCError SetEpilogue( SFXAnsiStringConstRef text )
Set the specified text to the Epilogue(suffix part) of the multi-part message.
SFCError SetFromField( SFXAnsiStringConstRef from )
Set the specified "from" mail address to the From field of the mail header.
SFCError SetPreamble( SFXAnsiStringConstRef text )
Set the specified text to the Preamble(prefix part) of this mail message.
SFCError SetSubjectField( SFXAnsiStringConstRef subject )
Set the specified "subject" text to the Subject field of the mail header.
SFXAnsiString Write( Bool isEncoding = true , UInt32 fieldMaxLen = 78 )
Write the mail message as a text.
Types
DocList
Prototype that represents an array of mail messages.

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

Description

This constructor does nothing.


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

Description

This destructor calls the SFXMailMessage::Clear function to clear the contents of this mail message.

Reference

SFXMailMessage::Clear


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

  • If succeeds: SFERR_NO_ERROR
  • If insufficient memory: SFERR_NO_MEMORY

Reference

SFXMailMessage::GetBccField | SFXMailMessage::ReplaceBccField | SFXMailMessage::AddField


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

  • If succeeds: SFERR_NO_ERROR
  • If insufficient memory: SFERR_NO_MEMORY

Reference

SFXMailMessage::GetCcField | SFXMailMessage::ReplaceCcField | SFXMailMessage::AddField


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

Return value

  • If succeeds: SFERR_NO_ERROR
  • If invalid field name or value: SFERR_INVALID_PARAM
  • If invalid format: SFERR_INVALID_FORMAT
  • If insufficient memory: SFERR_NO_MEMORY

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::RemoveField | 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

  • If succeeds: SFERR_NO_ERROR
  • If Content-Type is not "multipart": SFERR_INVALID_STATE
  • If insufficient memory: SFERR_NO_MEMORY

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

  • If succeeds: SFERR_NO_ERROR
  • If insufficient memory: SFERR_NO_MEMORY

Reference

SFXMailMessage::GetToField | SFXMailMessage::ReplaceToField | SFXMailMessage::AddField


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

  • If succeeds: 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

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 the 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 this mail message.
[ public ]
Void Clear(Void);

Reference

SFXMailMessage::~SFXMailMessage


SFXMailMessage::GetAttachedFile
Get the attached file of this mail message.
[ 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

  • If succeeds: 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.

[Caution] Encoding of the file name of attached data

RFC2231(MIME Parameter Value and Encoded Word Extensions) is not supported.

Reference

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


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

Argument

isDecoding

Specify whether or not to decode.

If true: This mail message encoded in the Q or B format will be decoded. This mail message in Japanese will be converted into the Shift-JIS code.

Default: true.

Return value

Return the value of Bcc field.

Reference

SFXMailMessage::AddBccField | SFXMailMessage::ReplaceBccField | SFXMailMessage::GetField


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

Argument

isDecoding

Specify whether or not to decode.

If true: This mail message encoded in the Quoted-Printable or Base64 format will be decoded. This 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 this mail message.
[ public, const ]
SFXAnsiStringConstRef GetBodyRef(Void);

Return value

Return the reference to the body of this mail message.

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

Description

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

Reference

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


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

Argument

isDecoding

Specify whether or not to decode.

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

Default: true.

Return value

Return the body of this 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 this mail message.
[ public, const ]
SFXAnsiString GetCcField(
    Bool isDecoding = true   // whether or not to decode
);

Argument

isDecoding

Specify whether or not to decode.

If true: This mail message encoded in the Q or B format will be decoded. This mail message in Japanese will be converted into the Shift-JIS code.

Default: true.

Return value

Return the value of Cc field.

Reference

SFXMailMessage::AddCcField | SFXMailMessage::ReplaceCcField | SFXMailMessage::GetField


SFXMailMessage::GetContentType
Get the value of Content-Type of this 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

  • If succeeds: 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 of this mail message.
[ public, const ]
SFXDate GetDateField(Void);

Return value

Return the value of the Date field(SFXDate).

Reference

SFXMailUtility::ParseDate | SFXDate


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: This mail message encoded in the Quoted-Printable or Base64 format will be decoded. This 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 the specified field of the mail header of this mail message.
[ 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: This mail message encoded in the Quoted-Printable or Base64 format will be decoded. This 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 the specified field exists. Specify null if unnecessary.

Return value

Return the value of the 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::HasField | SFXMailMessage::RemoveField | SFXMailMessage::GetFieldList


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

Return value

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

Description

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

The validity of the field names will not be checked when editing the header of this 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::RemoveField | SFXMailMessage::HasField | SFXMailMessage::RemoveField | SFXMailMessage::GetField | SFXProperty


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

Argument

isDecoding

Specify whether or not to decode.

If true: This mail message encoded in the Q or B format will be decoded. This mail message in Japanese will be converted into the Shift-JIS code.

Default: true.

Return value

Return From field value.

Reference

SFXMailMessage::SetFromField | SFXMailMessage::GetField


SFXMailMessage::GetMultipartMessage
Get the 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(SFXMailMessage instance).

Description

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

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 internal messages in the multi-part message.
[ public, const ]
UInt32 GetMultipartSize(Void);

Return value

Return the number of 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: This mail message encoded in the Quoted-Printable or Base64 format will be decoded. This 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 of this mail message.
[ public, const ]
SFXAnsiString GetSubjectField(
    Bool isDecoding = true   // whether or not to decode
);

Argument

isDecoding

Specify whether or not to decode.

If true: This mail message encoded in the Q or B format will be decoded. This mail message in Japanese will be converted into the Shift-JIS code.

Default: true.

Return value

Return the value of Subject field.

Description

[Caution] Encoding of the Subject field

RFC2231(MIME Parameter Value and Encoded Word Extensions) is not supported.

Reference

SFXMailMessage::SetSubjectField | SFXMailMessage::GetField


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

Argument

isDecoding

Specify whether or not to decode.

If true: This mail message encoded in the Q or B format will be decoded. This 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::AddToField | SFXMailMessage::ReplaceToField | SFXMailMessage::GetField


SFXMailMessage::HasField
Check whether or not the mail header has the 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::RemoveField | SFXMailMessage::GetField | SFXMailMessage::GetFieldList


SFXMailMessage::IsMultipart
Check whether or not this is a multi-part message.
[ 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 specified text and read it as a 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

  • If succeeds: SFERR_NO_ERROR
  • If the start or end argument is null: SFERR_INVALID_PARAM
  • If start > end: SFERR_INVALID_FORMAT
  • If insufficient memory: SFERR_NO_MEMORY

Description

This function can be used for the multi-part message.

Reference

SFXMailMessage::Write | SFXMailMessage::ParseHeaderOnly


SFXMailMessage::ParseHeaderOnly
Parse the specified text, and only the header is read as a 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

  • If succeeds: SFERR_NO_ERROR
  • If the start or end argument is null: SFERR_INVALID_PARAM
  • If start > end: 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.

Reference

SFXMailMessage::ReplaceToField | SFXMailMessage::ReplaceCcField | SFXMailMessage::ReplaceBccField | SFXMailMessage::AddField | SFXMailMessage::HasField | SFXMailMessage::RemoveField | SFXMailMessage::GetField | SFXMailMessage::GetFieldList


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

Argument

bcc

Specify the value of Bcc field to replace with.

Return value

  • If succeeds: SFERR_NO_ERROR
  • If insufficient memory: SFERR_NO_MEMORY

Reference

SFXMailMessage::AddBccField | SFXMailMessage::GetBccField | SFXMailMessage::ReplaceField


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

Argument

cc

Specify the value of Cc field to replace with.

Return value

  • If succeeds: SFERR_NO_ERROR
  • If insufficient memory: SFERR_NO_MEMORY

Reference

SFXMailMessage::AddCcField | SFXMailMessage::GetCcField | SFXMailMessage::ReplaceField


SFXMailMessage::ReplaceField
Replace the value of the specified field of the mail header with the 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

  • If succeeds: SFERR_NO_ERROR
  • If field name or value is invalid: SFERR_INVALID_PARAM
  • If format is invalid: SFERR_INVALID_FORMAT
  • If insufficient memory: SFERR_NO_MEMORY

Description

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

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

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

Reference

SFXMailMessage::AddField | SFXMailMessage::HasField | SFXMailMessage::RemoveField | 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 To field to replace with.

Return value

  • If succeeds: SFERR_NO_ERROR
  • If insufficient memory: SFERR_NO_MEMORY

Reference

SFXMailMessage::AddToField | SFXMailMessage::GetToField | SFXMailMessage::ReplaceField


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

Argument

text

Body of the mail message.

Return value

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

Description

[Caution] Multi-part message

This 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 this 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

  • If succeeds: SFERR_NO_ERROR
  • If insufficient memory: SFERR_NO_MEMORY

Description

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

Reference

SFXMailMessage::GetContentType | SFXMailMessage::IsMultipart


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

Return value

  • If succeeds: 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::SetPreamble | SFXMailMessage::IsMultipart


SFXMailMessage::SetFromField
Set the 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 From field.

Return value

  • If succeeds: SFERR_NO_ERROR
  • If insufficient memory: SFERR_NO_MEMORY

Reference

SFXMailMessage::GetFromField | SFXMailMessage::ReplaceField


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

Return value

  • If succeeds: 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::SetEpilogue | SFXMailMessage::IsMultipart


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

Argument

subject

Specify the value of Subject field.

Return value

  • If succeeds: SFERR_NO_ERROR
  • If insufficient memory: SFERR_NO_MEMORY

Reference

SFXMailMessage::GetSubjectField | SFXMailMessage::ReplaceField


SFXMailMessage::Write
Write the mail message as a 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 a text. If "true" is set to the isEncode argument, it is automatically converted into a appropriate character-code for sending mail.

Description

[Caution] Encoding of the Subject field and the file name of attached data

RFC2231(MIME Parameter Value and Encoded Word Extensions) is not supported.

Reference

SFXMailMessage::Parse


SFXMailMessage::DocList
Prototype that represents an array of mail messages.
typedef SFXArray<SFXMailMessagePtr> DocList