PrevNextUpHome SophiaFramework UNIVERSE 5.3
SFXSMTP
Class for processing the SMTP protocol.
#include <SFXSMTP.h.hpp>
class SFXSMTP;
SFMTYPEDEFCLASS(SFXSMTP)

Collaboration diagram

 Collaboration diagram of SFXSMTPClass

Description

Procedure to send a SMTP mail

  1. Create the SFXSMTP instance. At this time, resources for sending a SMTP mail are not allocated.
  2. To perform the initialization for sending a SMTP mail, call the SFXSMTP::Open function. And then to connect to the SMTP server, call the SFXSMTP::Connect function. In the SFXSMTP::Connect function, register a callback function which will be notified of the completion of sending a SMTP mail.
  3. A SMTP mail can be sent when the connection to the SMTP server is established.
  4. Send a SMTP command to the SMTP server using the function such as SFXSMTP::SendCommand.(*)
  5. The callback function registered using the SFXSMTP::Connect function will be notified when the response to a SMTP command from the SMTP server is received.
  6. Get the response code and response text using the SFXSMTP::GetResponseCode and SFXSMTP::GetResponseText functions respectively.
  7. When finish sending a SMTP mail, call the SFXSMTP::SendQuitCommand function to send the QUIT command to the SMTP server. And finally after confirming the response from the SMTP server, call the SFXSMTP::Close function to terminate the connection to the SMTP server.
[Note] Note
(*)For the SMTP commands such as HELO or EHLO, special functions such as SFXSMTP::SendHeloCommand or SFXSMTP::SendEhloCommand are provided for sending, and functions such as SFXSMTP::GetHeloResponse or SFXSMTP::GetEhloResponse are provided for obtaining the responses.
[Note] Detailed information on the SMTP protocol

SMTP specification : RFC2821 (Simple Mail Transfer Protocol)

Example 834. Implementation of the SFXSMTPSender class

/***************************************************************************************
****************************************************************************************
***
***     File            : SFXSMTPSender.f.hpp
***
****************************************************************************************
****************************************************************************************/

#ifndef __SOPHIAFRAMEWORK_SFXSMTPSENDER_FHPP
#define __SOPHIAFRAMEWORK_SFXSMTPSENDER_FHPP

#include <SFXGeneral/SFXEnvironment.h.hpp>

SFMTYPEDEFCLASS(SFXSMTPSENDER)

#endif // __SOPHIAFRAMEWORK_SFXSMTPSENDER_FHPP //


/***************************************************************************************
****************************************************************************************
***
***     File            : SFXSMTPSender.h.hpp
***
****************************************************************************************
****************************************************************************************/

#ifndef __SOPHIAFRAMEWORK_SFXSMTPSENDER_HHPP
#define __SOPHIAFRAMEWORK_SFXSMTPSENDER_HHPP

#include <SFXGeneral/SFXEnvironment.h.hpp>
#include <SFXProtocol/SFXMail/SFXSMTPSender.f.hpp>
#include <SFXProtocol/SFXMail/SFXSMTP.h.hpp>
#include <SFXCollection/SFXArray.h.hpp>
#include <SFXProtocol/SFXMail/SFXMailMessage.f.hpp>

class SFXSMTPSender {
    SFMSEALCOPY(SFXSMTPSender)
    public:
        enum ProgressEnum {
            PROGRESS_NONE                       = 0,
            PROGRESS_CONNECT,
            PROGRESS_EHLO,
            PROGRESS_HELO,
            PROGRESS_AUTH,
            PROGRESS_AUTHRESP1,
            PROGRESS_AUTHRESP2,
            PROGRESS_MAIL,
            PROGRESS_RCPT,
            PROGRESS_DATA,
            PROGRESS_DATATEXT,
            PROGRESS_QUIT,
            PROGRESS_ERRORQUIT,
            PROGRESS_DONE
        };
        enum AuthEnum {
            AUTH_NONE                           = 0,
            AUTH_PLAIN,
            AUTH_LOGIN,
            AUTH_CRAM_MD5,
            AUTH_DIGEST_MD5
        };
    private:
        enum StateEnum {
            STATE_STANDBY                       = 0,
            STATE_SENDING
        };

    public:
        typedef Void                            (*CallbackSPP)                  (SFCError error, VoidPtr reference);

    private:
                StateEnum                       _state;
                ProgressEnum                    _progress;
                ProgressEnum                    _previous;
                CallbackSPP                     _spp;
                VoidPtr                         _reference;
                AuthEnum                        _auth;
                SFXAnsiString                   _user;
                SFXAnsiString                   _password;
                SFXSocketAddress                _server;
                SFXAnsiString                   _client;
                SFXAnsiString                   _from;
                SFXArray<SFXAnsiStringPtr>      _toList;
                SFXAnsiString                   _message;
                SFXSMTP                         _smtp;
                SInt16                          _index;
                Bool                            _quit;
                Bool                            _isSSL;
                UInt32                          _sslTrustMode;

    public:
        explicit                                SFXSMTPSender                   (Void);
                                                ~SFXSMTPSender                  (Void);
                SFXSMTPRef                      GetSFXSMTP                      (Void);
                ProgressEnum                    GetProgress                     (Void) const;
                Void                            SetSSLMode                      (Bool isSSL);
                Bool                            GetSSLMode                      (Void) const;
                Void                            SetTrustMode                    (UInt32 sslTrustMode);
                UInt32                          GetTrustMode                    (Void) const;
                Void                            Cancel                          (Void);
                SFCError                        SetHostName                     (SFXAnsiStringConstRef host);
                SFCError                        SetServer                       (SFXSocketAddressConstRef server);
                SFCError                        SetAuthorization                (SFXSMTPSender::AuthEnum auth, SFXAnsiStringConstRef user, SFXAnsiStringConstRef password);
                SFCError                        SetFrom                         (SFXAnsiStringConstRef from);
                Void                            ClearTo                         (Void);
                SFCError                        AddTo                           (SFXAnsiStringConstRef to);
                SFCError                        SendMessage                     (SFXMailMessagePtr message, CallbackSPP spp, VoidPtr reference);
                SFCError                        SendText                        (SFXAnsiStringConstRef text, CallbackSPP spp, VoidPtr reference);
                Bool                            IsQuit                          (Void);
    private:
                SFCError                        ProceedConnect                  (UInt16 code);
                SFCError                        ProceedEhlo                     (UInt16 code);
                SFCError                        ProceedHelo                     (UInt16 code);
                SFCError                        ProceedAuth                     (UInt16 code);
                SFCError                        ProceedAuthresp1                (UInt16 code);
                SFCError                        ProceedAuthresp2                (UInt16 code);
                SFCError                        ProceedMail                     (UInt16 code);
                SFCError                        ProceedRcpt                     (UInt16 code);
                SFCError                        ProceedData                     (UInt16 code);
                SFCError                        ProceedDataText                 (UInt16 code);
                Void                            ProceedError                    (Void);
                Void                            FinishSend                      (SFCError err);
                SFCError                        SetBrackets                     (SFXAnsiStringConstRef string, SFXAnsiStringPtr result);
                XALLBACK_DECLARE_SFXSMTP(OnSMTP)
};

#define     XALLBACK_DECLARE_SFXSMTPSENDER(FUNCTION)                            XALLBACK_DECLARE_SFXSMTP(FUNCTION)

#include <SFXProtocol/SFXMail/SFXSMTPSender.i.hpp>


#endif // __SOPHIAFRAMEWORK_SFXSMTPSENDER_HHPP //


/***************************************************************************************
****************************************************************************************
***
***     File            : SFXSMTPSender.i.hpp
***
****************************************************************************************
****************************************************************************************/

#ifndef __SOPHIAFRAMEWORK_SFXSMTPSENDER_IHPP
#define __SOPHIAFRAMEWORK_SFXSMTPSENDER_IHPP

#include <SFXGeneral/SFXEnvironment.h.hpp>

/*public */inline SFXSMTPRef SFXSMTPSender::GetSFXSMTP(Void)
{
    return _smtp;
}// SFXSMTPSender::GetSFXSMTP //

/*public */inline SFXSMTPSender::ProgressEnum SFXSMTPSender::GetProgress(Void) const
{
    return _progress;
}// SFXSMTPSender::GetProgress //

/*public */inline Void SFXSMTPSender::SetSSLMode(Bool isSSL)
{
    _isSSL = isSSL;
    return;
}// SFXSMTPSender::SetSSLMode //

/*public */inline Bool SFXSMTPSender::GetSSLMode(Void) const
{
    return _isSSL;
}// SFXSMTPSender::GetSSLMode //

/*public */inline Void SFXSMTPSender::SetTrustMode(UInt32 sslTrustMode)
{
    _sslTrustMode = sslTrustMode;
    return;
}// SFXSMTPSender::SetTrustMode //

/*public */inline UInt32 SFXSMTPSender::GetTrustMode(Void) const
{
    return _sslTrustMode;
}// SFXSMTPSender::GetTrustMode //

/*public */inline SFCError SFXSMTPSender::SetHostName(SFXAnsiStringConstRef host)
{
    return _client.Set(host);
}// SFXSMTPSender::SetHostName //

/*public */inline SFCError SFXSMTPSender::SetServer(SFXSocketAddressConstRef server)
{
    return _server.Set(server);
}// SFXSMTPSender::SetServer //

/*public */inline SFCError SFXSMTPSender::SetFrom(SFXAnsiStringConstRef from)
{
    return _from.Set(from);
}// SFXSMTPSender::SetFrom //

/*public */inline Bool SFXSMTPSender::IsQuit(Void)
{
    return _quit;
}// SFXSMTPSender::IsQuit //

#define     XALLBACK_IMPLEMENT_SFXSMTPSENDER(TYPE, FUNCTION, ERROR)             XALLBACK_IMPLEMENT_SFXSMTP(TYPE, FUNCTION, ERROR)

#endif // __SOPHIAFRAMEWORK_SFXSMTPSENDER_IHPP //


/***************************************************************************************
****************************************************************************************
***
***     File            : SFXSMTPSender.i.cpp
***
****************************************************************************************
****************************************************************************************/

#include <SFXProtocol/SFXMail/SFXSMTPSender.h.hpp>
#include <SFXProtocol/SFXMail/SFXMailMessage.h.hpp>
#include <SFXProtocol/SFXMail/SFXMailUtility.h.hpp>

/*public */SFXSMTPSender::SFXSMTPSender(Void) : _state(STATE_STANDBY), _progress(PROGRESS_NONE), _auth(AUTH_NONE), _quit(false), _isSSL(false), _sslTrustMode(SSL_TRUST_MODE_FAIL)
{
}// SFXSMTPSender::SFXSMTPSender //

/*public */SFXSMTPSender::~SFXSMTPSender(Void)
{
    Cancel();
}// SFXSMTPSender::~SFXSMTPSender //

/*public */Void SFXSMTPSender::Cancel(Void)
{
    _state = STATE_STANDBY;
    _progress = PROGRESS_NONE;
    _spp = null;
    _reference = null;
    _server.Set(0, 0);
    _from.Clear();
    ClearTo();
    _message.Clear();
    _smtp.Close();
}// SFXSMTPSender::Cancel //

/*public */SFCError SFXSMTPSender::SetAuthorization(SFXSMTPSender::AuthEnum auth, SFXAnsiStringConstRef user, SFXAnsiStringConstRef password)
{
    SFCError error;

    if ((error = _user.Set(user)) == SFERR_NO_ERROR) {
        if ((error = _password.Set(password)) == SFERR_NO_ERROR) {
            _auth = auth;
        }
    }
    return error;
}// SFXSMTPSender::SetAuthorization //

/*public */Void SFXSMTPSender::ClearTo(Void)
{
    SFXArray<SFXAnsiStringPtr>::Iterator itor;
    SFXAnsiStringPtr string;

    itor = _toList.GetFirstIterator();
    while (itor.HasNext()) {
        string = itor.GetNext();
        ::delete string;
    }
    _toList.Clear();
}// SFXSMTPSender::ClearTo //

/*public */SFCError SFXSMTPSender::AddTo(SFXAnsiStringConstRef to)
{
    SFCError error;
    SFXAnsiStringPtr string;

    if ((string = ::new SFXAnsiString(to)) != null) {
        error = _toList.InsertLast(string);
    }
    else {
        error = SFERR_NO_MEMORY;
    }
    return error;
}// SFXSMTPSender::AddTo //

/*public */SFCError SFXSMTPSender::SendMessage(SFXMailMessagePtr message, CallbackSPP spp, VoidPtr reference)
{
    SFCError error(SFERR_NO_ERROR);
    SFBNetMgrSmp net;
    SFXAnsiString temp;
    SInt32 r0, r1;
    SFXProperty property;
    SFXAnsiStringPtr mail;

    if (!_server.Get().IsEmpty()) {
        if (error == SFERR_NO_ERROR) {
            if (_from.IsEmpty()) {
                _from = message->GetFromField();
            }
            if (_toList.IsEmpty()) {
                if ((error = SFXMailUtility::ParseMailboxList(message->GetToField(), &property)) == SFERR_NO_ERROR) {
                    if ((error = SFXMailUtility::ParseMailboxList(message->GetCcField(), &property)) == SFERR_NO_ERROR) {
                        if ((error = SFXMailUtility::ParseMailboxList(message->GetBccField(), &property)) == SFERR_NO_ERROR) {
                            r1 = property.GetSize();
                            for (r0 = 0; r0 < r1; ++r0) {
                                if ((mail = ::new SFXAnsiString) != null) {
                                    if ((error = mail->Set(property.GetValue(r0))) == SFERR_NO_ERROR) {
                                        if ((error = _toList.InsertLast(mail)) != SFERR_NO_ERROR) {
                                            break;
                                        }
                                    }
                                    else {
                                        break;
                                    }
                                }
                                else {
                                    error = SFERR_NO_MEMORY;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
        if (error == SFERR_NO_ERROR) {
            if (message->GetBccField().IsEmpty()) {
                error = _message.Set(message->Write());
            }
            else {
                if ((error = temp.Set(message->Write())) == SFERR_NO_ERROR) {
                    if ((r0 = temp.FirstIndexOf("BCC:", SINT32_MINIMUM, false)) > -1) {
                        r1 = temp.FirstIndexOf("\r\n", r0);
                        if ((error = _message.Set(temp.Substring(0, r0))) == SFERR_NO_ERROR) {
                            error = _message.Add(temp.Substring(r1 + 2, temp.GetLength()));
                        }
                    }
                    else {
                        error = SFERR_FAILED;
                    }
                }
            }
        }
        if (error == SFERR_NO_ERROR) {
            if (!_from.IsEmpty() && !_toList.IsEmpty()) {
                _smtp.Close();
                if ((error = _smtp.Open()) == SFERR_NO_ERROR) {
                    _smtp.SetSSLMode(_isSSL);
                    if ((error = _smtp.SetTrustMode(_sslTrustMode)) == SFERR_NO_ERROR) {
                        if ((error = _smtp.Connect(_server, XALLBACK_INTERNAL(OnSMTP))) == SFERR_NO_ERROR) {
                            _state = STATE_SENDING;
                            _progress = PROGRESS_CONNECT;
                            _spp = spp;
                            _reference = reference;
                            _quit = false;
                        }
                    }
                    if (error != SFERR_NO_ERROR) {
                        _smtp.Close();
                    }
                }
            }
            else {
                error = SFERR_INVALID_PARAM;
            }
        }
    }
    else {
        error = SFERR_FAILED;
    }
    return error;
}// SFXSMTPSender::SendMessage //

/*public */SFCError SFXSMTPSender::SendText(SFXAnsiStringConstRef text, CallbackSPP spp, VoidPtr reference)
{
    SFCError error(SFERR_NO_ERROR);
    _message.Set(text); // temp
    if (!_client.IsEmpty() && !_from.IsEmpty() && !_toList.IsEmpty()) {
        _smtp.Close();
        if ((error = _smtp.Open()) == SFERR_NO_ERROR) {
            _smtp.SetSSLMode(_isSSL);
            if ((error = _smtp.SetTrustMode(_sslTrustMode)) == SFERR_NO_ERROR) {
                if ((error = _smtp.Connect(_server, XALLBACK_INTERNAL(OnSMTP))) == SFERR_NO_ERROR) {
                    _state = STATE_SENDING;
                    _progress = PROGRESS_CONNECT;
                    _spp = spp;
                    _reference = reference;
                    _quit = false;
                }
            }
            if (error != SFERR_NO_ERROR) {
                _smtp.Close();
            }
        }
    }
    else {
        error = SFERR_INVALID_PARAM;
    }
    return error;
}// SFXSMTPSender::SendText //

/*private */XALLBACK_IMPLEMENT_SFXSMTP(SFXSMTPSender, OnSMTP, error)
{
    SIntN code;

    if (error == SFERR_NO_ERROR) {
        code = _smtp.GetResponseCode();
        switch (_progress) {
            case PROGRESS_CONNECT:
                error = ProceedConnect(code);
                break;
            case PROGRESS_EHLO:
                error = ProceedEhlo(code);
                break;
            case PROGRESS_HELO:
                error = ProceedHelo(code);
                break;
            case PROGRESS_AUTH:
                error = ProceedAuth(code);
                break;
            case PROGRESS_AUTHRESP1:
                error = ProceedAuthresp1(code);
                break;
            case PROGRESS_AUTHRESP2:
                error = ProceedAuthresp1(code);
                break;
            case PROGRESS_MAIL:
                error = ProceedMail(code);
                break;
            case PROGRESS_RCPT:
                error = ProceedRcpt(code);
                break;
            case PROGRESS_DATA:
                error = ProceedData(code);
                break;
            case PROGRESS_DATATEXT:
                error = ProceedDataText(code);
                break;
            case PROGRESS_ERRORQUIT:
                _progress = PROGRESS_DONE;
                FinishSend(_previous);
                break;
            case PROGRESS_QUIT:
                _progress = PROGRESS_DONE;
                FinishSend(SFERR_NO_ERROR);
                break;
            case PROGRESS_DONE:
            case PROGRESS_NONE:
            default:
                FinishSend(PROGRESS_NONE);
                break;
        }
    }
    if (error != SFERR_NO_ERROR) {
        FinishSend(_progress);
    }
}// XALLBACK_IMPLEMENT_SFXSMTP(SFXSMTPSender, OnSMTP, error) //

/*private */SFCError SFXSMTPSender::ProceedConnect(UInt16 code)
{
    SFCError error(SFERR_NO_ERROR);
    SFXInetAddress address;

    if (code == 220) {
        _progress = PROGRESS_EHLO;
        if (_client.IsEmpty()) {
            address = SFXInetAddress::LocalInetAddress();
            if (!address.Get().IsEmpty()) {
                error = _client.Set(address.Get());
            }
            else {
                error = SFERR_FAILED;
            }
        }
        error = _smtp.SendEhloCommand(_client);
    }
    else {
        ProceedError();
    }
    return error;
}// SFXSMTPSender::ProceedConnect //

/*private */SFCError SFXSMTPSender::ProceedEhlo(UInt16 code)
{
    SFCError error(SFERR_NO_ERROR);
    SFXSMTP::AuthEnum auth(SFXSMTP::AUTH_NONE);
    SFXAnsiString temp;

    if (_auth == AUTH_NONE) {
        if (code == 250) {
            _progress = PROGRESS_MAIL;
            if ((error = SetBrackets(_from, &temp)) == SFERR_NO_ERROR) {
                error = _smtp.SendMailCommand(temp);
            }
        }
        else {
            _progress = PROGRESS_HELO;
            error = _smtp.SendHeloCommand(_client);
        }
    }
    else {
        if (code == 250) {
            _progress = PROGRESS_AUTH;
            switch (_auth) {
                case AUTH_NONE:
                    auth = SFXSMTP::AUTH_NONE;
                    break;
                case AUTH_PLAIN:
                    auth = SFXSMTP::AUTH_PLAIN;
                    break;
                case AUTH_LOGIN:
                    auth = SFXSMTP::AUTH_LOGIN;
                    break;
                case AUTH_CRAM_MD5:
                    auth = SFXSMTP::AUTH_CRAM_MD5;
                    break;
                case AUTH_DIGEST_MD5:
                    auth = SFXSMTP::AUTH_DIGEST_MD5;
                    break;
                default:
                    break;
            }
            error = _smtp.SendAuthCommand(auth);
        }
        else {
            ProceedError();
        }
    }
    return error;
}// SFXSMTPSender::ProceedEhlo //

/*private */SFCError SFXSMTPSender::ProceedHelo(UInt16 code)
{
    SFCError error(SFERR_NO_ERROR);
    SFXAnsiString temp;

    if (code == 220) {
        _progress = PROGRESS_MAIL;
        if ((error = SetBrackets(_from, &temp)) == SFERR_NO_ERROR) {
            error = _smtp.SendMailCommand(temp);
        }
    }
    else {
        ProceedError();
    }
    return error;
}// SFXSMTPSender::ProceedHelo //

/*private */SFCError SFXSMTPSender::ProceedAuth(UInt16 code)
{
    SFCError error(SFERR_NO_ERROR);

    if (code == 334) {
        _progress = PROGRESS_AUTHRESP1;
        switch (_auth) {
            case AUTH_PLAIN:
                error = _smtp.SendAuthResponse(_user, _password);
                break;
            case AUTH_LOGIN:
                error = _smtp.SendAuthResponse(_user);
                break;
            case AUTH_CRAM_MD5:
                error = _smtp.SendAuthResponse(_user, _password, _smtp.GetResponseText());
                break;
            case AUTH_NONE:
            case AUTH_DIGEST_MD5:
            default:
                // DIGEST_MD5 has not been supported yet.
                _previous = _progress;
                _progress = PROGRESS_ERRORQUIT;
                if ((error = _smtp.SendQuitCommand()) == SFERR_NO_ERROR) {
                    _quit = true;
                }
                break;
        }
    }
    else {
        ProceedError();
    }
    return error;
}// SFXSMTPSender::ProceedAuth //

/*private */SFCError SFXSMTPSender::ProceedAuthresp1(UInt16 code)
{
    SFCError error(SFERR_NO_ERROR);
    SFXAnsiString temp;

    if (code == 334) {
        if (_auth == AUTH_LOGIN) {
            _progress = PROGRESS_AUTHRESP2;
            error = _smtp.SendAuthResponse(_password);
        }
    }
    else if (code == 235) {
        _progress = PROGRESS_MAIL;
        if ((error = SetBrackets(_from, &temp)) == SFERR_NO_ERROR) {
            error = _smtp.SendMailCommand(temp);
        }
    }
    else {
        ProceedError();
    }
    return error;
}// SFXSMTPSender::ProceedAuthresp1 //

/*private */SFCError SFXSMTPSender::ProceedAuthresp2(UInt16 code)
{
    SFCError error(SFERR_NO_ERROR);
    SFXAnsiString temp;

    if (code == 235) {
        _progress = PROGRESS_MAIL;
        if ((error = SetBrackets(_from, &temp)) == SFERR_NO_ERROR) {
            error = _smtp.SendMailCommand(temp);
        }
    }
    else {
        ProceedError();
    }
    return error;
}// SFXSMTPSender::ProceedAuthresp2 //

/*private */SFCError SFXSMTPSender::ProceedMail(UInt16 code)
{
    SFXAnsiString temp;
    SFCError error(SFERR_NO_ERROR);

    if (code == 250) {
        _progress = PROGRESS_RCPT;
        _index = 0;
        if ((error = SetBrackets(*_toList[0], &temp)) == SFERR_NO_ERROR) {
            error = _smtp.SendRcptCommand(temp);
        }
    }
    else {
        ProceedError();
    }
    return error;
}// SFXSMTPSender::ProceedMail //

/*private */SFCError SFXSMTPSender::ProceedRcpt(UInt16 code)
{
    SFXAnsiString temp;
    SFCError error(SFERR_NO_ERROR);

    if (code == 250 || code == 251) {
        ++_index;
        if (_index < _toList.GetSize()) {
            if ((error = SetBrackets(*_toList[_index], &temp)) == SFERR_NO_ERROR) {
                error = _smtp.SendRcptCommand(temp);
            }
        }
        else {
            _progress = PROGRESS_DATA;
            error = _smtp.SendDataCommand();
        }
    }
    else {
        ProceedError();
    }
    return error;
}// SFXSMTPSender::ProceedRcpt //

/*private */SFCError SFXSMTPSender::ProceedData(UInt16 code)
{
    SFCError error(SFERR_NO_ERROR);

    if (code == 354) {
        _progress = PROGRESS_DATATEXT;
        error = _smtp.SendDataText(_message);
    }
    else {
        ProceedError();
    }
    return error;
}// SFXSMTPSender::ProceedData //

/*private */SFCError SFXSMTPSender::ProceedDataText(UInt16 /*code*/)
{
    SFCError error(SFERR_NO_ERROR);

    _progress = PROGRESS_QUIT;
    if ((error = _smtp.SendQuitCommand()) == SFERR_NO_ERROR) {
        _quit = true;
    }
    return error;
}// SFXSMTPSender::ProceedDataText //

/*private */Void SFXSMTPSender::ProceedError(Void)
{
    _previous = _progress;
    _progress = PROGRESS_ERRORQUIT;
    if (_smtp.SendQuitCommand() == SFERR_NO_ERROR) {
        _quit = true;
    }
    return;
}// SFXSMTPSender::ProceedError //

/*private */Void SFXSMTPSender::FinishSend(SFCError error)
{
    _state = STATE_STANDBY;
    _smtp.Close();
    if (_spp != null) {
        _spp(error, _reference);
    }
    return;
}// SFXSMTPSender::FinishSend //

/*private */SFCError SFXSMTPSender::SetBrackets(SFXAnsiStringConstRef string, SFXAnsiStringPtr result)
{
    SFCError error(SFERR_NO_ERROR);

    if (string.StartsWith('<') && string.EndsWith('>')) {
        error = result->Set(string);
    }
    else {
        if ((error = result->Set('<')) == SFERR_NO_ERROR) {
            if ((error = result->Add(string)) == SFERR_NO_ERROR) {
                error = result->Add('>');
            }
        }
    }
    return error;
}// SFXSMTPSender::SetBrackets //

Reference

SFXSMTPSender | Mail Sending | RFC2821(Simple Mail Transfer Protocol)

Member

Constructor/Destructor
SFXSMTP( Void )
Constructor of the SFXSMTP class.
~SFXSMTP( Void )
Destructor of the SFXSMTP class.
Public Functions
Void Cancel( Void )
Cancel sending a SMTP mail.
Void Close( Void )
Close the connection to the SMTP server.
SFCError Connect( SFXSocketAddressConstRef address , CallbackSPP spp , VoidPtr reference )
Connect to the SMTP server.
SFCError GetEhloResponse( SFXAnsiStringPtr domain , SFXAnsiStringPtr greet , SFXAnsiStringHandle extList , UInt32Ptr extCount )
Get the response to the EHLO command.
SFCError GetHeloResponse( SFXAnsiStringPtr domain , SFXAnsiStringPtr greet )
Get the response to the HELO command.
SFCError GetLocalAddress( SFXSocketAddressPtr result )
Get the local IP address and port number.
SFCError GetRemoteAddress( SFXSocketAddressPtr result )
Get the remote IP address and port number.
SInt32 GetResponseCode( Void )
Get the response code.
SFXAnsiString GetResponseText( Void )
Get the response text.
SFCError GetResponseText( SFXAnsiStringPtr result )
Get the response text.
Bool GetSSLMode( Void )
Get the SSL connection mode.
UInt32 GetTrustMode( Void )
Get the SSL trust mode.
SFCError Open( Void )
Perform the initialization for connecting to the SMTP server.
SFCError SendAuthCommand( AuthEnum auth )
Send the AUTH command.
SFCError SendAuthResponse( SFXAnsiStringConstRef str1 , SFXAnsiStringConstRef str2 = SFXAnsiString::EmptyInstance() , SFXAnsiStringConstRef str3 = SFXAnsiString::EmptyInstance() )
Send the answer to the response of the AUTH command.
SFCError SendCommand( ACharConstPtr command , UInt32 size )
Send the SMTP command.
SFCError SendCommand( SFXAnsiStringConstRef command )
Send the SMTP command.
SFCError SendDataCommand( Void )
Send the DATA command.
SFCError SendDataText( SFXAnsiStringConstRef text )
Send the mail text.
SFCError SendEhloCommand( SFXAnsiStringConstRef hostName )
Send the ELHO command.
SFCError SendHeloCommand( SFXAnsiStringConstRef hostName )
Send the HELO command.
SFCError SendMailCommand( SFXAnsiStringConstRef from )
Send the MAIL command.
SFCError SendNoopCommand( Void )
Send the NOOP command.
SFCError SendQuitCommand( Void )
Send the QUIT command.
SFCError SendRcptCommand( SFXAnsiStringConstRef to )
Send the RCPT command.
SFCError SendRsetCommand( Void )
Send the RSET command.
Void SetSSLMode( Bool isSSL )
Set the SSL connection mode.
SFCError SetTrustMode( UInt32 sslTrustMode )
Set the SSL trust mode.
Types
AuthEnum
Constants that represent the SMTP authorization methods.
CallbackSPP
Type that represents the callback function specified in the SFXSMTP::Connect function.

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

Description

This constructor turns the SSL connection mode off.

Resources for sending a SMTP mail will not be allocated when the SFXSMTP instance is created. Those resources will be allocated after calling the SFXSMTP::Open function.

Reference

SFXSMTP::SetSSLMode | SFXSMTP::Open


SFXSMTP::~SFXSMTP
Destructor of the SFXSMTP class.
[ public, virtual ]
~SFXSMTP(Void);

Description

This destructor closes the SMTP connection.

Reference

SFXSMTP::Close


SFXSMTP::Cancel
Cancel sending a SMTP mail.
[ public ]
Void Cancel(Void);

Description

This function calls the SFXTCPSocket::Cancel function internally.

Reference

SFXSMTP::Close


SFXSMTP::Close
Close the connection to the SMTP server.
[ public ]
Void Close(Void);

Description

Resources for sending a SMTP mail will be released. If during processing, it will be canceled.

[Note] How to terminate the connection to the SMTP server

After confirming the response to the QUIT command sent by the SFXSMTP::SendQuitCommand function from the SMTP server, terminate the connection to the SMTP server using the SFXSMTP::Close function

Reference

SFXSMTP::Cancel | SFXSMTP::SendQuitCommand | SFXSMTP::Connect | RFC2821(Simple Mail Transfer Protocol)


SFXSMTP::Connect
Connect to the SMTP server.
[ public ]
SFCError Connect(
    SFXSocketAddressConstRef address   // IP address and port number of the SMTP server
    CallbackSPP spp                    // callback function
    VoidPtr reference                  // argument for the callback
);

Argument

address

Specify the IP address and port number of the SMTP server.

Return value

  • If succeeds: SFERR_NO_ERROR
  • If socket is not opened or it has already been connected (including connection processing): SFERR_INVALID_STATE
  • If IP address and port number of the SMTP server have not been set: SFERR_INVALID_STATE
  • If failed to create the SFBNetMgr instance: SFERR_FAILED
  • If insufficient memory: SFERR_NO_MEMORY
  • For other network errors: get error value by the BREW API ISOCKET_GetLastError function.

Description

[Caution] Error when connecting to the SMTP server

An error occurred when connecting to the SMTP server is notified to the callback function.

Reference

SFXSMTP::Open | SFXSMTP::Close | SFXSMTP::CallbackSPP | BREW API ISOCKET_GetLastError


SFXSMTP::GetEhloResponse
Get the response to the EHLO command.
[ public, const ]
SFCError GetEhloResponse(
    SFXAnsiStringPtr domain       // domain name
    SFXAnsiStringPtr greet        // greeting message
    SFXAnsiStringHandle extList   // extension command
    UInt32Ptr extCount            // number of extension commands
);

Argument

domain

Specify a pointer to the variable to store the domain name obtained from the SMTP server. Specify null if unnecessary.

greet

Specify a pointer to the variable to store the greeting message obtained from the SMTP server. Specify null if unnecessary.

extList

Specify a handle to store the pointer to the list of extension commands obtained from the SMTP server. An array of SFXAnsiString is passed. This array must be released by the caller using the delete[] operator. Specify null if unnecessary.

extCount

Specify a pointer to the variable to store the number of extension commands obtained from the SMTP server. Specify null if unnecessary.

Return value

  • If succeeds: SFERR_NO_ERROR
  • If connection has not been established: SFERR_INVALID_STATE
  • If response code is not 250: SFERR_FAILED
  • If insufficient memory: SFERR_NO_MEMORY

Description

This function gets the response to the ELHO command sent by the SFXSMTP::SendEhloCommand function.

The ELHO command is the command to start the session of sending a SMTP mail.

Reference

SFXSMTP::SendEhloCommand | RFC2821: 4.1.1.1 Extended HELLO (EHLO) or HELLO (HELO)


SFXSMTP::GetHeloResponse
Get the response to the HELO command.
[ public, const ]
SFCError GetHeloResponse(
    SFXAnsiStringPtr domain   // domain name
    SFXAnsiStringPtr greet    // greeting message
);

Argument

domain

Specify a pointer to the variable to store the domain name obtained from the SMTP server. Specify null if unnecessary.

greet

Specify a pointer to the variable to store the greeting message obtained from the SMTP server. Specify null if unnecessary.

Return value

  • If succeeds: SFERR_NO_ERROR
  • If connection has not been established: SFERR_INVALID_STATE
  • If response code is not 250: SFERR_FAILED
  • If insufficient memory: SFERR_NO_MEMORY

Description

This function gets the response to the HELO command sent by the SFXSMTP::SendHeloCommand command.

The HELO command is the command to start the session of sending a SMTP mail.

Reference

SFXSMTP::SendHeloCommand | RFC2821: 4.1.1.1 Extended HELLO (EHLO) or HELLO (HELO)


SFXSMTP::GetLocalAddress
Get the local IP address and port number.
[ public, const ]
SFCError GetLocalAddress(
    SFXSocketAddressPtr result   // pointer to the variable to store the local IP address and port number
);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If connection has not been established: SFERR_INVALID_STATE
  • If the result argument is null: SFERR_INVALID_PARAM
  • For other network errors: get error value by the BREW API ISOCKET_GetLastError function.

Description

This function gets the local IP address and port number of the internal socket.

Reference

SFXInetAddress::LocalInetAddress | SFXTCPSocket::GetLocalAddress | BREW API ISOCKET_GetLastError


SFXSMTP::GetRemoteAddress
Get the remote IP address and port number.
[ public, const ]
SFCError GetRemoteAddress(
    SFXSocketAddressPtr result   // pointer to the variable to store the remote IP address and port number
);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If connection has not been established: SFERR_INVALID_STATE
  • If the result argument is null: SFERR_INVALID_PARAM
  • For other network errors: get error value by the BREW API ISOCKET_GetLastError function.

Description

This function gets the remote IP address and port number of the peer connected by the internal socket.

Reference

SFXTCPSocket::GetRemoteAddress | BREW API ISOCKET_GetLastError


SFXSMTP::GetResponseCode
Get the response code.
[ public, const ]
SInt32 GetResponseCode(Void);

Return value

Return the 3-digit response code (decimal number).

Description

Detailed information on the response code of the SMTP command: RFC2821: 4.2 SMTP Replies

Reference

SFXSMTP::GetResponseText | SFXSMTP::SendCommand | SFXSMTP::Connect | RFC2821: 4.2 SMTP Replies


SFXSMTP::GetResponseText
Get the response text.
[ public, const ]
SFXAnsiString GetResponseText(Void);
[ public, const ]
SFCError GetResponseText(
    SFXAnsiStringPtr result   // pointer to the variable to store the response text from the SMTP server
);

Argument

result

Specify a pointer to the variable to store the response text obtained from the SMTP server.

Return value

  • If succeeds: SFERR_NO_ERROR
  • If connection has not been established: SFERR_INVALID_STATE
  • If insufficient memory: SFERR_NO_MEMORY

Description

[Note] About response text

Response text is the partial response message, which is the text removed the response code at the beginning and succeeding whitespace or hyphen("-") from the response message from the SMTP server.

Reference

SFXSMTP::GetResponseCode | SFXSMTP::SendCommand | SFXSMTP::Connect | RFC2821: 4.2 SMTP Replies


SFXSMTP::GetSSLMode
Get the SSL connection mode.
[ public, const ]
Bool GetSSLMode(Void);

Return value

  • If the SSL connection mode is turned on: true
  • Otherwise : false

Reference

SFXSMTP::SetSSLMode


SFXSMTP::GetTrustMode
Get the SSL trust mode.
[ public, const ]
UInt32 GetTrustMode(Void);

Description

The SSL trust mode can be one of the following values.

  • SSL_TRUST_MODE_FAIL
  • SSL_TRUST_MODE_CHECK
  • SSL_TRUST_MODE_IGNORE
  • SSL_TRUST_MODE_ALWAYS
[Note] Note
Reference: ISSL_NegotiateV in the BREW API Reference

Reference

SFXSMTP::SetTrustMode | BREW API ISSL_NegotiateV


SFXSMTP::Open
Perform the initialization for connecting to the SMTP server.
[ public ]
SFCError Open(Void);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If socket has already been opened: SFERR_INVALID_STATE
  • If failed to create the instance of the SFBNetMgr or SFBSSL class: SFERR_FAILED
  • If failed: AEE_NET_ERROR

Description

The SFXSSLSocket::Open function is called internally in this function. When the TCP connection is used, the SFXSSLSocket::Permit function will be called in the internal callback function of the SFXSMTP::Connect function.

Reference

SFXSSLSocket::Open | SFXSSLSocket::Permit | SFXSMTP::Connect | SFXSMTP::Close


SFXSMTP::SendAuthCommand
Send the AUTH command.
[ public ]
SFCError SendAuthCommand(
    AuthEnum auth   // authorization method
);

Argument

auth

Specify authorization method.

Return value

  • If succeeds: SFERR_NO_ERROR
  • If connection has not been established: SFERR_INVALID_STATE
  • If insufficient memory: SFERR_NO_MEMORY

Description

The AUTH command is the command for the SMTP authorization.

After receiving the response to the EHLO command, send the AUTH command to the SMTP server. PLAIN, LOGIN, and CRAM-MD5 are available for the authorization method.

[Caution] Method to get the communication error and the command error

Only the error about the internal processing of this function will be returned as return value.

The communication error is notified to the callback function registered using the SFXSMTP::Connect function.

To check whether the command succeeded or not, use the SFXSMTP::GetResponseCode function.

Example

The code below is to perform the CRAM-MD5 authorization.

smtp.SendAuthCommand(SFXSMTP::AUTH_CRAM_MD5);

Reference

SFXSMTP::SendAuthResponse | SFXSMTP::GetResponseCode | SFXSMTP::GetResponseText | SFXSMTP::AuthEnum | SFXSMTP::Connect | RFC2554: SMTP Service Extension for Authentication


SFXSMTP::SendAuthResponse
Send the answer to the response of the AUTH command.
[ public ]
SFCError SendAuthResponse(
    SFXAnsiStringConstRef str1                                    // string 1 (differs depending on the authorization method)
    SFXAnsiStringConstRef str2 = SFXAnsiString::EmptyInstance()   // string 2 (differs depending on the authorization method)
    SFXAnsiStringConstRef str3 = SFXAnsiString::EmptyInstance()   // string 3 (differs depending on the authorization method)
);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If connection has not been established: SFERR_INVALID_STATE
  • If insufficient memory: SFERR_NO_MEMORY

Description

The AUTH command is the command for the SMTP authorization.

After sending the AUTH command to the SMTP server using the SFXSMTP::SendAuthCommand function, send the answer to its response from the SMTP server(The arguments differs depending on the authorization method).

In case of PLAIN:

  1. str1: username
  2. str2: password
  3. str3: not used

In case of LOGIN: First, execute SendAuthResponse(user). Second, execute SendAuthResponse(password) after receiving the response from the SMTP server.

In case of CRAM-MD5:

  1. str1: username
  2. str2: password
  3. str3 : Challenge code (text returned from the SMTP server)

[Caution] Method to get the communication error and the command error

Only the error about the internal processing of this function will be returned as return value.

The communication error is notified to the callback function registered using the SFXSMTP::Connect function.

To check whether the command succeeded or not, use the SFXSMTP::GetResponseCode function.

Example

Perform the CRAM-MD5 authorization.

smtp.SendAuthResponse("user", "password", smtp.GetResponseText());

Reference

SFXSMTP::SendAuthResponse | SFXSMTP::GetResponseCode | SFXSMTP::GetResponseText | SFXSMTP::Connect | RFC2554: SMTP Service Extension for Authentication


SFXSMTP::SendCommand
Send the SMTP command.
[ public ]
SFCError SendCommand(
    ACharConstPtr command   // SMTP command
    UInt32 size             // size of the SMTP command
);
[ public ]
SFCError SendCommand(
    SFXAnsiStringConstRef command   // SMTP command
);

Argument

command

Specify a pointer to the SMTP command to be sent to the SMTP server.

Return value

  • If succeeds: SFERR_NO_ERROR
  • If connection has not been established: SFERR_INVALID_STATE
  • If insufficient memory: SFERR_NO_MEMORY

Description

[Caution] Method to get the communication error and the command error

Only the error about the internal processing of this function will be returned as return value.

The communication error is notified to the callback function registered using the SFXSMTP::Connect function.

To check whether the command succeeded or not, use the SFXSMTP::GetResponseCode function.

Reference

SFXSMTP::GetResponseCode | SFXSMTP::GetResponseText | SFXSMTP::Connect | RFC2821: 4.1 SMTP Commands


SFXSMTP::SendDataCommand
Send the DATA command.
[ public ]
SFCError SendDataCommand(Void);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If connection has not been established: SFERR_INVALID_STATE
  • If insufficient memory: SFERR_NO_MEMORY

Description

The DATA command is the command to be sent immediately before the mail text.

When the SMTP server receives this command, it sends 354 as response code which means to request for the mail text. After this, send the mail text using the SFXSMTP::SendDataText function.

[Caution] Method to get the communication error and the command error

Only the error about the internal processing of this function will be returned as return value.

The communication error is notified to the callback function registered using the SFXSMTP::Connect function.

To check whether the command succeeded or not, use the SFXSMTP::GetResponseCode function.

Reference

SFXSMTP::SendDataText | SFXSMTP::GetResponseCode | SFXSMTP::GetResponseText | SFXSMTP::Connect | RFC2821: 4.1.1.4 DATA (DATA)


SFXSMTP::SendDataText
Send the mail text.
[ public ]
SFCError SendDataText(
    SFXAnsiStringConstRef text   // mail
);

Argument

text

Specify a reference to the mail text.

Return value

  • If succeeds: SFERR_NO_ERROR
  • If connection has not been established: SFERR_INVALID_STATE
  • If insufficient memory: SFERR_NO_MEMORY

Description

This function sends a mail text of mail header and its body. The mail header contains information such as host name of sender, mail address of sender, mail address of recipient, etc.

The mail text needs to be sent immediately after the SFXSMTP::SendDataCommand function.

[Caution] Method to get the communication error and the command error

Only the error about the internal processing of this function will be returned as return value.

The communication error is notified to the callback function registered using the SFXSMTP::Connect function.

To check whether the command succeeded or not, use the SFXSMTP::GetResponseCode function.

Reference

SFXSMTP::SendDataCommand | SFXSMTP::GetResponseCode | SFXSMTP::GetResponseText | SFXSMTP::Connect | RFC2821: 4.1.1.4 DATA (DATA)


SFXSMTP::SendEhloCommand
Send the ELHO command.
[ public ]
SFCError SendEhloCommand(
    SFXAnsiStringConstRef hostName   // host name
);

Argument

hostName

Specify a reference to the host name.

Return value

  • If succeeds: SFERR_NO_ERROR
  • If connection has not been established: SFERR_INVALID_STATE
  • If insufficient memory: SFERR_NO_MEMORY

Description

The ELHO command is the command to start the session of sending a SMTP mail.

The response message is obtained using the SFXSMTP::GetEhloResponse function.

[Caution] Method to get the communication error and the command error

Only the error about the internal processing of this function will be returned as return value.

The communication error is notified to the callback function registered using the SFXSMTP::Connect function.

To check whether the command succeeded or not, use the SFXSMTP::GetResponseCode function.

Reference

SFXSMTP::GetEhloResponse | SFXSMTP::GetResponseCode | SFXSMTP::GetResponseText | SFXSMTP::Connect | RFC2821: 4.1.1.1 Extended HELLO (EHLO) or HELLO (HELO)


SFXSMTP::SendHeloCommand
Send the HELO command.
[ public ]
SFCError SendHeloCommand(
    SFXAnsiStringConstRef hostName   // host name
);

Argument

hostName

Specify a reference to the host name.

Return value

  • If succeeds: SFERR_NO_ERROR
  • If connection has not been established: SFERR_INVALID_STATE
  • If insufficient memory: SFERR_NO_MEMORY

Description

HELO command is the command to start the session of sending a SMTP mail.

The response message is obtained using the SFXSMTP::GetHeloResponse function. The HELO command is for the compatibility with old servers, and is not recommended to use. Commonly, the ELHO command (SFXSMTP::SendEhloCommand function) is used.

[Caution] Method to get the communication error and the command error

Only the error about the internal processing of this function will be returned as return value.

The communication error is notified to the callback function registered using the SFXSMTP::Connect function.

To check whether the command succeeded or not, use the SFXSMTP::GetResponseCode function.

Reference

SFXSMTP::SendEhloCommand | SFXSMTP::GetHeloResponse | SFXSMTP::GetResponseCode | SFXSMTP::GetResponseText | SFXSMTP::Connect | RFC2821: 4.1.1.1 Extended HELLO (EHLO) or HELLO (HELO)


SFXSMTP::SendMailCommand
Send the MAIL command.
[ public ]
SFCError SendMailCommand(
    SFXAnsiStringConstRef from   // mail address of the sender
);

Argument

from

Specify a reference to the mail address of the sender, which must be enclosed by <>.

Return value

  • If succeeds: SFERR_NO_ERROR
  • If connection has not been established: SFERR_INVALID_STATE
  • If insufficient memory: SFERR_NO_MEMORY

Description

The MAIL command is the command to set the mail address of the sender.

[Caution] Method to get the communication error and the command error

Only the error about the internal processing of this function will be returned as return value.

The communication error is notified to the callback function registered using the SFXSMTP::Connect function.

To check whether the command succeeded or not, use the SFXSMTP::GetResponseCode function.

Reference

SFXSMTP::GetResponseCode | SFXSMTP::GetResponseText | SFXSMTP::Connect | RFC2821: 4.1.1.2 MAIL (MAIL)


SFXSMTP::SendNoopCommand
Send the NOOP command.
[ public ]
SFCError SendNoopCommand(Void);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If connection has not been established: SFERR_INVALID_STATE
  • If insufficient memory: SFERR_NO_MEMORY

Description

The NOOP command is the command to check the connection to the SMTP server.

When the SMTP server receives the NOOP command, it returns only the response message.

[Caution] Method to get the communication error and the command error

Only the error about the internal processing of this function will be returned as return value.

The communication error is notified to the callback function registered using the SFXSMTP::Connect function.

To check whether the command succeeded or not, use the SFXSMTP::GetResponseCode function.

Reference

SFXSMTP::GetResponseCode | SFXSMTP::GetResponseText | SFXSMTP::Connect | RFC2821: 4.1.1.9 NOOP (NOOP)


SFXSMTP::SendQuitCommand
Send the QUIT command.
[ public ]
SFCError SendQuitCommand(Void);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If connection has not been established: SFERR_INVALID_STATE
  • If insufficient memory: SFERR_NO_MEMORY

Description

The QUIT command is the command to terminate the session of sending a SMTP mail.

[Note] How to terminate the connection to the SMTP server

After confirming the response to the QUIT command sent by the SFXSMTP::SendQuitCommand function from the SMTP server, terminate the connection to the SMTP server using the SFXSMTP::Close function

[Caution] Method to get the communication error and the command error

Only the error about the internal processing of this function will be returned as return value.

The communication error is notified to the callback function registered using the SFXSMTP::Connect function.

To check whether the command succeeded or not, use the SFXSMTP::GetResponseCode function.

Reference

SFXSMTP::GetResponseCode | SFXSMTP::GetResponseText | SFXSMTPSender::IsQuit | SFXSMTP::Connect | RFC2821: 4.1.1.10 QUIT (QUIT)


SFXSMTP::SendRcptCommand
Send the RCPT command.
[ public ]
SFCError SendRcptCommand(
    SFXAnsiStringConstRef to   // mail address of the recipient
);

Argument

to

Specify a reference to the mail address of the recipient, which must be enclosed by <>.

Return value

  • If succeeds: SFERR_NO_ERROR
  • If connection has not been established: SFERR_INVALID_STATE
  • If insufficient memory: SFERR_NO_MEMORY

Description

The RCPT command is the command to set the mail address of the recipient.

[Caution] Method to get the communication error and the command error

Only the error about the internal processing of this function will be returned as return value.

The communication error is notified to the callback function registered using the SFXSMTP::Connect function.

To check whether the command succeeded or not, use the SFXSMTP::GetResponseCode function.

Reference

SFXSMTP::GetResponseCode | SFXSMTP::GetResponseText | SFXSMTP::Connect | RFC2821: 4.1.1.3 RECIPIENT (RCPT)


SFXSMTP::SendRsetCommand
Send the RSET command.
[ public ]
SFCError SendRsetCommand(Void);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If connection has not been established: SFERR_INVALID_STATE
  • If insufficient memory: SFERR_NO_MEMORY

Description

The RSET command is the command to reset the session of sending a SMTP mail.

[Caution] Method to get the communication error and the command error

Only the error about the internal processing of this function will be returned as return value.

The communication error is notified to the callback function registered using the SFXSMTP::Connect function.

To check whether the command succeeded or not, use the SFXSMTP::GetResponseCode function.

Reference

SFXSMTP::GetResponseCode | SFXSMTP::GetResponseText | SFXSMTP::Connect | RFC2821: 4.1.1.5 RESET (RSET)


SFXSMTP::SetSSLMode
Set the SSL connection mode.
[ public ]
Void SetSSLMode(
    Bool isSSL   // whether or not to use SSL connection or not
);

Description

To use SSL connection, specify true in the "isSSL" argument.

Reference

SFXSMTP::GetSSLMode | SFXSMTP::SFXSMTP


SFXSMTP::SetTrustMode
Set the SSL trust mode.
[ public ]
SFCError SetTrustMode(
    UInt32 sslTrustMode   // SSL trust mode
);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If socket has been closed: SFERR_INVALID_STATE

Description

One of the following values are available for the SSL trust mode:

  • SSL_TRUST_MODE_FAIL: Default, fail on trust errors.
  • SSL_TRUST_MODE_CHECK: Suspend on trust errors so they can be checked and ignored.
  • SSL_TRUST_MODE_IGNORE: Ignore all trust errors.
  • SSL_TRUST_MODE_ALWAYS: Always suspend so trust can always be checked.
[Note] Note
Reference: ISSL_NegotiateV in the BREW API Reference

Reference

SFXSMTP::GetTrustMode | SFXSMTP::Connect | SFXSSLSocket::SetTrustMode | BREW API ISSL_NegotiateV


SFXSMTP::AuthEnum
Constants that represent the SMTP authorization methods.
enum AuthEnum {
    AUTH_NONE,
    AUTH_PLAIN,
    AUTH_LOGIN,
    AUTH_CRAM_MD5,
    AUTH_DIGEST_MD5
};

Description

The SMTP authorization method is specified by the following constants using SFXSMTPSender::SetAuthorization function.

AUTH_NONE

SMTP authorization is not used.

AUTH_PLAIN

Represent PLAIN authorization.

AUTH_LOGIN

Represent LOGIN authorization.

AUTH_CRAM_MD5

Represent CRAM-MD5 authorization.

AUTH_DIGEST_MD5

Represent DIGEST-MD5 authorization (in the current version, DIGEST-MD5 authorization cannot be used.)

Reference

SFXSMTPSender::SetAuthorization


SFXSMTP::CallbackSPP
Type that represents the callback function specified in the SFXSMTP::Connect function.
typedef Void(* SFXSMTP::CallbackSPP)(SFCError error, VoidPtr reference)

Description

SFXSMTP::CallbackSPP is the prototype for the callback function used in the SFXSMTP class. This callback function is registered using the SFXSMTP::Connect function. The result of sending a SMTP mail is notified to this callback function.

For the 1st argument "error": SFERR_NO_ERROR will be set if sending a SMTP mail succeeds, but an error code other than SFERR_NO_ERROR will be set if it fails.

For the 2nd argument "reference": A parameter specified by the SFXSMTP::Connect function (in general, instance of the SFXSMTP class) is passed.

Reference

SFXSMTP::Connect