SophiaFramework UNIVERSE 5.3 |
Procedure to send a SMTP mail
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. |
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 //
SFXSMTPSender | Mail Sending | RFC2821(Simple Mail Transfer Protocol)
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.
|
[ public, explicit ] SFXSMTP(Void);
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.
[ public, virtual ] ~SFXSMTP(Void);
This destructor closes the SMTP connection.
[ public ] Void Cancel(Void);
This function calls the SFXTCPSocket::Cancel function internally.
[ public ] Void Close(Void);
Resources for sending a SMTP mail will be released. If during processing, it will be canceled.
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 |
SFXSMTP::Cancel | SFXSMTP::SendQuitCommand | SFXSMTP::Connect | RFC2821(Simple Mail Transfer Protocol)
[ public ] SFCError Connect( SFXSocketAddressConstRef address // IP address and port number of the SMTP server CallbackSPP spp // callback function VoidPtr reference // argument for the callback );
Specify the IP address and port number of the SMTP server.
Error when connecting to the SMTP server | |
---|---|
An error occurred when connecting to the SMTP server is notified to the callback function. |
SFXSMTP::Open | SFXSMTP::Close | SFXSMTP::CallbackSPP | BREW API ISOCKET_GetLastError
[ public, const ] SFCError GetEhloResponse( SFXAnsiStringPtr domain // domain name SFXAnsiStringPtr greet // greeting message SFXAnsiStringHandle extList // extension command UInt32Ptr extCount // number of extension commands );
Specify a pointer to the variable to store the domain name obtained from the SMTP server. Specify null if unnecessary.
Specify a pointer to the variable to store the greeting message obtained from the SMTP server. Specify null if unnecessary.
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.
Specify a pointer to the variable to store the number of extension commands obtained from the SMTP server. Specify null if unnecessary.
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.
[ public, const ] SFCError GetHeloResponse( SFXAnsiStringPtr domain // domain name SFXAnsiStringPtr greet // greeting message );
Specify a pointer to the variable to store the domain name obtained from the SMTP server. Specify null if unnecessary.
Specify a pointer to the variable to store the greeting message obtained from the SMTP server. Specify null if unnecessary.
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.
[ public, const ] SFCError GetLocalAddress( SFXSocketAddressPtr result // pointer to the variable to store the local IP address and port number );
This function gets the local IP address and port number of the internal socket.
SFXInetAddress::LocalInetAddress | SFXTCPSocket::GetLocalAddress | BREW API ISOCKET_GetLastError
[ public, const ] SFCError GetRemoteAddress( SFXSocketAddressPtr result // pointer to the variable to store the remote IP address and port number );
This function gets the remote IP address and port number of the peer connected by the internal socket.
[ public, const ] SInt32 GetResponseCode(Void);
Return the 3-digit response code (decimal number).
Detailed information on the response code of the SMTP command: RFC2821: 4.2 SMTP Replies
SFXSMTP::GetResponseText | SFXSMTP::SendCommand | SFXSMTP::Connect | RFC2821: 4.2 SMTP Replies
[ public, const ] SFXAnsiString GetResponseText(Void);
[ public, const ] SFCError GetResponseText( SFXAnsiStringPtr result // pointer to the variable to store the response text from the SMTP server );
Specify a pointer to the variable to store the response text obtained from the SMTP server.
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. |
SFXSMTP::GetResponseCode | SFXSMTP::SendCommand | SFXSMTP::Connect | RFC2821: 4.2 SMTP Replies
[ public, const ] Bool GetSSLMode(Void);
[ public, const ] UInt32 GetTrustMode(Void);
The SSL trust mode can be one of the following values.
Note | |
---|---|
Reference: ISSL_NegotiateV in the BREW API Reference |
[ public ] SFCError Open(Void);
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.
SFXSSLSocket::Open | SFXSSLSocket::Permit | SFXSMTP::Connect | SFXSMTP::Close
[ public ] SFCError SendAuthCommand( AuthEnum auth // authorization method );
Specify authorization method.
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.
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. |
The code below is to perform the CRAM-MD5 authorization.
smtp.SendAuthCommand(SFXSMTP::AUTH_CRAM_MD5);
SFXSMTP::SendAuthResponse | SFXSMTP::GetResponseCode | SFXSMTP::GetResponseText | SFXSMTP::AuthEnum | SFXSMTP::Connect | RFC2554: SMTP Service Extension for Authentication
[ 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) );
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:
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:
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. |
Perform the CRAM-MD5 authorization.
smtp.SendAuthResponse("user", "password", smtp.GetResponseText());
SFXSMTP::SendAuthResponse | SFXSMTP::GetResponseCode | SFXSMTP::GetResponseText | SFXSMTP::Connect | RFC2554: SMTP Service Extension for Authentication
[ public ] SFCError SendCommand( ACharConstPtr command // SMTP command UInt32 size // size of the SMTP command );
[ public ] SFCError SendCommand( SFXAnsiStringConstRef command // SMTP command );
Specify a pointer to the SMTP command to be sent to the SMTP server.
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. |
SFXSMTP::GetResponseCode | SFXSMTP::GetResponseText | SFXSMTP::Connect | RFC2821: 4.1 SMTP Commands
[ public ] SFCError SendDataCommand(Void);
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.
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. |
SFXSMTP::SendDataText | SFXSMTP::GetResponseCode | SFXSMTP::GetResponseText | SFXSMTP::Connect | RFC2821: 4.1.1.4 DATA (DATA)
[ public ] SFCError SendDataText( SFXAnsiStringConstRef text // mail );
Specify a reference to the mail text.
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.
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. |
SFXSMTP::SendDataCommand | SFXSMTP::GetResponseCode | SFXSMTP::GetResponseText | SFXSMTP::Connect | RFC2821: 4.1.1.4 DATA (DATA)
[ public ] SFCError SendEhloCommand( SFXAnsiStringConstRef hostName // host name );
Specify a reference to the host name.
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.
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. |
SFXSMTP::GetEhloResponse | SFXSMTP::GetResponseCode | SFXSMTP::GetResponseText | SFXSMTP::Connect | RFC2821: 4.1.1.1 Extended HELLO (EHLO) or HELLO (HELO)
[ public ] SFCError SendHeloCommand( SFXAnsiStringConstRef hostName // host name );
Specify a reference to the host name.
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.
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. |
SFXSMTP::SendEhloCommand | SFXSMTP::GetHeloResponse | SFXSMTP::GetResponseCode | SFXSMTP::GetResponseText | SFXSMTP::Connect | RFC2821: 4.1.1.1 Extended HELLO (EHLO) or HELLO (HELO)
[ public ] SFCError SendMailCommand( SFXAnsiStringConstRef from // mail address of the sender );
Specify a reference to the mail address of the sender, which must be enclosed by <>.
The MAIL command is the command to set the mail address of the sender.
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. |
SFXSMTP::GetResponseCode | SFXSMTP::GetResponseText | SFXSMTP::Connect | RFC2821: 4.1.1.2 MAIL (MAIL)
[ public ] SFCError SendNoopCommand(Void);
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.
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. |
SFXSMTP::GetResponseCode | SFXSMTP::GetResponseText | SFXSMTP::Connect | RFC2821: 4.1.1.9 NOOP (NOOP)
[ public ] SFCError SendQuitCommand(Void);
The QUIT command is the command to terminate the session of sending a SMTP mail.
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 |
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. |
SFXSMTP::GetResponseCode | SFXSMTP::GetResponseText | SFXSMTPSender::IsQuit | SFXSMTP::Connect | RFC2821: 4.1.1.10 QUIT (QUIT)
[ public ] SFCError SendRcptCommand( SFXAnsiStringConstRef to // mail address of the recipient );
Specify a reference to the mail address of the recipient, which must be enclosed by <>.
The RCPT command is the command to set the mail address of the recipient.
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. |
SFXSMTP::GetResponseCode | SFXSMTP::GetResponseText | SFXSMTP::Connect | RFC2821: 4.1.1.3 RECIPIENT (RCPT)
[ public ] SFCError SendRsetCommand(Void);
The RSET command is the command to reset the session of sending a SMTP mail.
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. |
SFXSMTP::GetResponseCode | SFXSMTP::GetResponseText | SFXSMTP::Connect | RFC2821: 4.1.1.5 RESET (RSET)
To use SSL connection, specify true in the "isSSL" argument.
One of the following values are available for the SSL trust mode:
Note | |
---|---|
Reference: ISSL_NegotiateV in the BREW API Reference |
SFXSMTP::GetTrustMode | SFXSMTP::Connect | SFXSSLSocket::SetTrustMode | BREW API ISSL_NegotiateV
enum AuthEnum { AUTH_NONE, AUTH_PLAIN, AUTH_LOGIN, AUTH_CRAM_MD5, AUTH_DIGEST_MD5 };
The SMTP authorization method is specified by the following constants using SFXSMTPSender::SetAuthorization function.
SMTP authorization is not used.
Represent PLAIN authorization.
Represent LOGIN authorization.
Represent CRAM-MD5 authorization.
Represent DIGEST-MD5 authorization (in the current version, DIGEST-MD5 authorization cannot be used.)
typedef Void(* SFXSMTP::CallbackSPP)(SFCError error, VoidPtr reference)
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.
Copyright(c) 2002 - 2024 Sophia Cradle Incorporated All Rights Reserved. |