![]() ![]() ![]()
|
BREW C++ Class Library & GUI Framework & XML Middleware : SophiaFramework 4.1 |

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) | |
| Constructor/Destructor |
|---|
|
SFXSMTP( Void ) Constructor of SFXSMTP class.
|
|
~SFXSMTP( Void ) Destructor of 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
) 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 SMTP authorization methods.
|
|
CallbackSPP Prototype of the callback function.
|
[ public, explicit ] SFXSMTP(Void);
Resources for sending a SMTP mail will not be allocated when the instance of the SFXSMTP class is created. Those resources will be allocated after calling the SFXSMTP::Open function.
[ public, virtual ] ~SFXSMTP(Void);
The SFXSMTP::Close function needs to be called before destroying the instance of the SFXSMTP class.
[ public ] Void Cancel(Void);
The SFXTCPSocket::Cancel function is called internally in this function.
[ 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 | |
[ 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. | |
[ 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.
The ELHO command is the command to start the session of sending a SMTP mail.
The SFXSMTP::GetEhloResponse function gets the response to the ELHO command sent by the SFXSMTP::SendEhloCommand function.
[ 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.
The HELO command is the command to start the session of sending a SMTP mail.
The SFXSMTP::GetHeloResponse function gets the response to the HELO command sent by the SFXSMTP::SendHeloCommand command.
[ public, const ] SFCError GetLocalAddress( SFXSocketAddressPtr result // pointer to the variable to store the local IP address and port number );
![]() |
Local IP address may be changed |
|---|---|
There is a possibility that the local IP address may changed after connecting to the SMTP server. | |
[ public, const ] SFCError GetRemoteAddress( SFXSocketAddressPtr result // pointer to the variable to store the remote IP address and port number );
![]() |
Remote IP address may be changed |
|---|---|
There is a possibility that the remote IP address may be changed after connecting to the SMTP server. | |
[ public, const ] SInt32 GetResponseCode(Void);
Return the 3-digit response code (decimal number).
Detailed information on the response code of the SMTP command: RFC2821 ( Simple Mail Transfer Protocol )
[ 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. | |
[ public, const ] Bool GetSSLMode(Void);
[ public, const ] UInt32 GetTrustMode(Void);
The SSL trust mode can be one of the following values.
![]() |
Note |
|---|---|
| Detailed information: ISSL_NegotiateV in the BREW API Reference | |
[ public ] SFCError Open(Void);
The SFXTCPSocket::Open function is called internally in this function.
[ 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. | |
Perform the CRAM-MD5 authorization.
smtp.SendAuthCommand(SFXSMTP::AUTH_CRAM_MD5);
SFXSMTP::SendAuthResponse | SFXSMTP::GetResponseCode | SFXSMTP::GetResponseText | SFXSMTP::Connect
[ 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
[ 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
[ 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
[ public ] SFCError SendDataText( SFXAnsiStringConstRef text // mail );
Specify a reference to the mail text.
The SFXSMTP::SendDataText 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
[ 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
[ 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
[ 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
[ 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
[ 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 | SFXSMTP::Connect
[ 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
[ 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
To use SSL connection, set true to the "isSSL" parameter.
One of the following values are available for the SSL trust mode:
![]() |
Note |
|---|---|
| Detailed information: ISSL_NegotiateV in the BREW API Reference | |
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.
As 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.
As 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 - 2009 Sophia Cradle, Inc. All Rights Reserved. |
![]() ![]() ![]()
|