CSimpleSMTPClient

Simple API for sending Internet Emails (via SMTP).

[ SimpleEmailClient | Source | Keywords | Summary | Ancestors | All Members | Descendants ]

Quick Index

DESCRIPTION
USAGE
EXAMPLE
ADMINISTRATIVE
SEE ALSO

Class Summary

class CSimpleSMTPClient

{

public:
CSimpleSMTPClient(LPCTSTR lpszSMTPServerNames, UINT uPortNumber , UINT uTimeOut );
~CSimpleSMTPClient();
HRESULT SendEmail(LPCTSTR lpszFrom, LPCTSTR lpszTo, LPCTSTR lpszSubject, LPCTSTR lpszBody);
CString GetLastErrorMessage(void);
protected:
BOOL BuildListFromString(LPCTSTR lpszStringWithSeparators, CStringList &oList);
CString BuildStringFromList(CStringList &oList, LPCTSTR lpszSeparator);
CString BuildRFC822Address(LPCTSTR lpszAddress);
CString ExtractSMTPAddress(LPCTSTR lpszAddress);
BOOL GetHostName(CString &szFullyQualifiedHostName);
HRESULT SendEmailToServer(LPCTSTR lpszServerName, LPCTSTR lpszFrom, LPCTSTR lpszTo, LPCTSTR lpszSubject, LPCTSTR lpszBody);
}; // CSimpleSMTPClient

Back to the top of CSimpleSMTPClient


DESCRIPTION

This class provides a simple API to send Internet Emails via the Simple Mail Transfer Protocol (SMTP).

This class succeeded in sending email messages to the following SMTP servers:

Back to the top of CSimpleSMTPClient


USAGE

To use this class:

Back to the top of CSimpleSMTPClient


EXAMPLE

    // Create instance
    CSimpleSMTPClient oSMTPClient("smtp.mydomain.com");

HRESULT hResult = oSMTPClient.SendEmail("me@mydomain.com", "you@yourdomain.com", "This is my subject...", "This is the body text..."); if (FAILED(hResult)) {

// Log error

[...]

} else {

// Email sent successfully

[...]

}

Back to the top of CSimpleSMTPClient


ADMINISTRATIVE

Author Emmanuel KARTMANN

Date Tuesday 11/17/98

Back to the top of CSimpleSMTPClient


SEE ALSO

CSimpleSocket CSocket RFC822 RFC821

Back to the top of CSimpleSMTPClient


CSimpleSMTPClient(LPCTSTR lpszSMTPServerNames, UINT uPortNumber , UINT uTimeOut );

Purpose: create an instance of the class

Parameters:

in lpszSMTPServerNames
List of IP name or IP address of the SMTP Servers (string with names separated by commas).
in uPortNumber
SMTP port number (defaults to 25)
in uTimeOut
timeout (in milliseconds) for connection/send/receive (defaults to 30 seconds)

Return value : none (C++ constructor)

Description :

    CSimpleSMTPClient(LPCTSTR lpszSMTPServerNames, UINT uPortNumber = 25, UINT uTimeOut = 30000);

Back to the top of CSimpleSMTPClient


~CSimpleSMTPClient();

Purpose: delete an instance of the class

Parameters: none (C++ destructor)

Return value : none (C++ destructor)

Description :

    virtual ~CSimpleSMTPClient();

Back to the top of CSimpleSMTPClient


HRESULT SendEmail(LPCTSTR lpszFrom, LPCTSTR lpszTo, LPCTSTR lpszSubject, LPCTSTR lpszBody);

Purpose: send an email message (via SMTP)

Parameters:

in lpszFrom
message originator (one RFC822 address). You can use full addresses (e.g. "Emmanuel KARTMANN ") or raw addresses (e.g. "emmanuel@kartmann.com").
in lpszTo
message recipients (list of RFC822 addresses, separated by commas or semicolons). You can use full addresses (e.g. "Emmanuel KARTMANN ") or raw addresses (e.g. "emmanuel@kartmann.com").
in lpszSubject
message subject
in lpszBody
message body

Return value : HRESULT = S_OK (0) for success

Description : This function tries to send the email message using all known SMTP servers (see constructor). It calls function SendEmailToServer() until one server accepts to deliver the email message.

    HRESULT SendEmail(LPCTSTR lpszFrom, LPCTSTR lpszTo, LPCTSTR lpszSubject, LPCTSTR lpszBody);

Back to the top of CSimpleSMTPClient


CString GetLastErrorMessage(void);

Purpose: returns the last error message

Parameters: none

Return value : CString = last error message

Description : CAUTION: the current implementation is not thread-safe (there's only one message per class instance; you should not share the class instance between threads).

    CString GetLastErrorMessage(void);

Back to the top of CSimpleSMTPClient


BOOL BuildListFromString(LPCTSTR lpszStringWithSeparators, CStringList &oList);

Purpose: Builds a CStringList object with a string containing separators (e.g. list of SMTP addresses separated by commas ',')

Parameters:

in lpszStringWithSeparators
the string that will be parsed to build the list
out oList
the built list

Return value : BOOL = TRUE for success, FALSE otherwise

Description : The separator is either a comma (',') or a semicolon (';').

    BOOL BuildListFromString(LPCTSTR lpszStringWithSeparators, CStringList &oList);

Back to the top of CSimpleSMTPClient


CString BuildStringFromList(CStringList &oList, LPCTSTR lpszSeparator);

Purpose: Builds a string containing separators with a CStringList object with a string (e.g. list of SMTP addresses separated by commas ',')

Parameters:

in oList
the list of strings
in lpszSeparator
the separator used

Return value : CString = the built string

Description :

    CString BuildStringFromList(CStringList &oList, LPCTSTR lpszSeparator);

Back to the top of CSimpleSMTPClient


CString BuildRFC822Address(LPCTSTR lpszAddress);

Purpose: builds a RFC822 address from a plain string

Parameters:

in lpszAddress
a plain string (e.g. "emmanuel@kartmann.com")

Return value : CString = RFC822 address, e.g. ""

Description : If the parameter is already an RFC822 address, (e.g. "Emmanuel KARTMANN ") this function does nothing.

    CString BuildRFC822Address(LPCTSTR lpszAddress);

Back to the top of CSimpleSMTPClient


CString ExtractSMTPAddress(LPCTSTR lpszAddress);

Purpose: extract an SMTP address from a full RFC822 address

Parameters:

in lpszAddress
full address (e.g. "Emmanuel KARTMANN ")

Return value : CString = SMTP address (e.g. "emmanuel@kartmann.com")

Description : This function extracts everything between '<' and '>' in the input string. It's used because some SMTP servers reject full addresses.

    CString ExtractSMTPAddress(LPCTSTR lpszAddress);

Back to the top of CSimpleSMTPClient


BOOL GetHostName(CString &szFullyQualifiedHostName);

Purpose: return the fully qualified IP name of the local machine.

Parameters:

out szFullyQualifiedHostName
fully qualified (i.e. including domain name) IP name

Return value : BOOL = TRUE for success, FALSE otherwise

Description : The IP name is used as part of the SMTP protocol (in the "HELO" line).

    BOOL GetHostName(CString &szFullyQualifiedHostName);

Back to the top of CSimpleSMTPClient


HRESULT SendEmailToServer(LPCTSTR lpszServerName, LPCTSTR lpszFrom, LPCTSTR lpszTo, LPCTSTR lpszSubject, LPCTSTR lpszBody);

Purpose: send an email message (via SMTP)

Parameters:

in lpszServerName
IP Name (or address) of the SMTP server to connect to
in lpszFrom
message originator (one RFC822 address). You can use full addresses (e.g. "Emmanuel KARTMANN ") or raw addresses (e.g. "emmanuel@kartmann.com").
in lpszTo
message recipients (list of RFC822 addresses, separated by commas or semicolons). You can use full addresses (e.g. "Emmanuel KARTMANN ") or raw addresses (e.g. "emmanuel@kartmann.com").
in lpszSubject
message subject
in lpszBody
message body

Return value : HRESULT = S_OK (0) for success

Description : -

    HRESULT SendEmailToServer(LPCTSTR lpszServerName, LPCTSTR lpszFrom, LPCTSTR lpszTo, LPCTSTR lpszSubject, LPCTSTR lpszBody);

Back to the top of CSimpleSMTPClient


All Members

public:
HRESULT SendEmail(LPCTSTR lpszFrom, LPCTSTR lpszTo, LPCTSTR lpszSubject, LPCTSTR lpszBody);
CString GetLastErrorMessage(void);
protected:
BOOL BuildListFromString(LPCTSTR lpszStringWithSeparators, CStringList &oList);
CString BuildStringFromList(CStringList &oList, LPCTSTR lpszSeparator);
CString BuildRFC822Address(LPCTSTR lpszAddress);
CString ExtractSMTPAddress(LPCTSTR lpszAddress);
BOOL GetHostName(CString &szFullyQualifiedHostName);
HRESULT SendEmailToServer(LPCTSTR lpszServerName, LPCTSTR lpszFrom, LPCTSTR lpszTo, LPCTSTR lpszSubject, LPCTSTR lpszBody);

Back to the top of CSimpleSMTPClient


Ancestors

Class does not inherit from any other class.

Back to the top of CSimpleSMTPClient


Descendants

Class is not inherited by any others.

Back to the top of CSimpleSMTPClient


Generated from source by the Cocoon utilities on Tue Feb 08 17:47:03 2000 .

Report problems to jkotula@stratasys.com