Connecting to an SMTP Server


You ll start by looking at the simple snippet of code in Listing 24-1 to see how you can establish a connection to an SMTP server.

Listing 24.1: Initializing a Connection to an SMTP Server
start example
 1  #include <atlsmtpconnection.h>  2  #include <atlmime.h>  3  4  CoInitialize(NULL);  5  6  CSMTPConnection smtpConnection;  7  if (!smtpConnection.Connect("localhost"))  8  {  9    printf("Could not connect to SMTP server!\n");  10 } 
end example
 

Listing 24-1 is obviously very short, but we ll take a quick line-by-line look at it:

  • Lines 1 and 2: All of the public support for SMTP and MIME in ATL Server is implemented in the atlsmtpconnection.h and atlmime.h header files. These classes make use of some of the constants and utility functions defined in atlsmtputil.h.

  • Line 4: ATL Server uses the MLang services to help with the conversion between the local character set and Unicode. These services are exposed via COM interfaces, so COM must be initialized before ATL Server can query for these services. In general, MLang provides services for writing internationalized software for the Internet. We recommend looking up documentation in MSDN for the IMultiLanguage interface as a good start for learning about MLang.

  • Line 7: The name of the SMTP server you re connecting to will depend on your network setup. You can optionally specify a timeout for the connection; by default, the timeout is 10 seconds.

You ll spend this chapter looking at the major classes in ATL Server that support SMTP and MIME. You ll also take a look at how to implement some of the more common scenarios that SMTP and MIME are used for. In the next section you ll examine the CSMTPConnection class.




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