Managing Connections with CSMTPConnection


Most of the SMTP functionality in ATL Server is implemented using the CSMTPConnection class. CSMTPConnection manages connections and allows messages to be sent. In this section you ll look at how CSMTPConnection manages connections for you.

CSMTPConnection provides methods for connecting to an SMTP server, disconnecting from it, and determining whether or not you have a valid connection.

Caution  

An important point to remember is that CSMTPConnection isn t thread-safe, so you must be careful not to allow multithreaded access to it in your application.

Let s look at each method associated with managing connections in CSMTPConnection :

 BOOL Connect(LPCTSTR lpszHostName,                            DWORD  dwTimeout = 10000) throw() 

Connect must be called and it must execute successfully before you can send messages using CSMTPConnection . This method establishes a connection to the SMTP server specified by lpszHostName . A boolean value is returned to indicate success or failure. You can also specify an optional timeout value. Because CSMTPConnection is not thread-safe, if you must send messages from multiple threads in your application, you should maintain one CSMTPConnection per thread. You can, however, safely call Connect multiple times (after a successful connection, subsequent calls are ignored). Another connection won t be made until you call Disconnect . This method simply ends your connection to the SMTP connection and returns a boolean to indicate success or failure:

 inline BOOL Disconnect() throw() 

This method returns a boolean to indicate whether or not you have a valid connection to an SMTP server:

 inline BOOL Connected() throw() 

Now that you ve seen how to establish a connection to a SMTP server, you ll look at how to actually send messages over that connection in the next section.




ATL Server. High Performance C++ on. NET
Observing the User Experience: A Practitioners Guide to User Research
ISBN: B006Z372QQ
EAN: 2147483647
Year: 2002
Pages: 181

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net