Networking Tools: Thread-hot Internet Classes (int library)
#include <rw/toolpro/smtp.h> RWISmtpClient client;
thr, net, int, tls (and possibly std)
RWSmtpClient provides low-level access to the SMTP client-side protocol. The names of the methods parallel the names of the protocol actions. An RWISmtpClient object maintains a finite state machine to enforce correct SMTP protocol action ordering. In the case of misordered method invocation, an RWxmsg exception is thrown.
All client methods return RWIOUResults redeemable for a particular type of RWISmtpReply. RWISmtpReply and its subclass RWISmtpDataReply contain an encapsulation of standard SMTP protocol reply messages. RWISmtpDataReply returns additional data-related information.
RWISmtpClient objects are lightweight. They are implemented using the interface-implementation pattern. The RWISmtpClient itself is really a handle to an implementation that performs the protocol interaction.
#include <iostream.h> #include <rw/cstring.h> #include <rw/toolpro/sockport.h> #include <rw/toolpro/portstrm.h> #include <rw/toolpro/winsock.h> #include <rw/toolpro/smtpa.h> void main() { RWWinSockInfo info; RWISmtpClient client; // SMTP client object RWISmtpReply reply; // SMTP general reply RWISmtpDataReply dReply; // SMTP data reply try { // Connect to our SMTP server reply = client.connect("smtp.roguewave.com"); // Say hello from the local machine reply = client.helo("tsunami"); // Mail From: and To: reply = client.mail("customer.roguewave.com"); reply = client.rcpt("support.roguewave.com"); // Send a help message dReply = client.dataOpen(); dReply.portal().sendAtLeast("We've got a problem... \n"); dReply.portal().sendAtLeast("Please help immediately"); // Indicate it's the end of the message dReply = client.dataClose(); // Send more messages, if you like // Finally shut down the connection reply = client.quit(); } catch (const RWxmsg& m) { cout << "Error : " << m.why() << endl; } }
RWISmtpClient();
Constructs a default RWISmtpClient. Use the connect method to establish a connection with an SMTP server.
RWIOUResult<RWISmtpReply> connect(const RWCString& host, int port=25);
Establishes a connection with an SMTP server. The host argument is expected as an IP address or host domain name where the server resides. The port argument is the server port that the SMTP service is attached to, typically 25. A successful reply is normally in the 2XX family.
RWIOUResult<RWISmtpReply> dataClose();
Closes the body of the mail message opened with the dataOpen method. This method writes the body termination sequence <period><cr><lf>.
RWIOUResult<RWISmtpDataReply> dataOpen();
Performs the protocol DATA action. The DATA action informs the SMTP server that the following data should be considered the body of the message. By definition, the body of the message is terminated by a line containing only <period><cr><lf>.
The dataClose method inserts this sequence into the data stream, so you need not handle this task. Note that it is the user's responsibility to ensure that the data termination sequence is not contained within the body of the message. The global utility function rwAddPeriods() (see the "Utility Functions"section) may be used to help you format your message. A successful reply is normally in the 3XX family.
The method returns an RWIOUResult with a redeemable RWISmtpReply. Data (message body) can then be written to the socket portal that is returned from the RWISmtpReply portal method.
RWIOUResult<RWISmtpReply> expn(const RWCString& who);
Performs the protocol EXPN action. The who argument is the email address of the mail recipient. The EXPN action is similar to the VRFY action, except that some servers expand the email address if it is a mailing list. A successful reply is normally in the 2XX family if the email address is known by the destination.
RWIOUResult<RWISmtpReply> helo(const RWCString& localMachine);
Performs the protocol HELO action. The HELO action informs the SMTP server of the name of the client machine sending the mail, specified as the localMachine argument. A successful reply is normally in the 2XX family.
RWIOUResult<RWISmtpReply> mail(const RWCString& from);
Performs the protocol MAIL action. The from argument is the email address of the mail sender. The MAIL action informs the SMTP server of the sender of the mail message. A successful reply is normally in the 2XX family.
RWIOUResult<RWISmtpReply> noop();
Performs the protocol NOOP action. The NOOP action is often used to test whether the established connection to the SMTP server is still valid before the client sends a message. A successful reply is normally in the 2XX family.
RWIOUResult<RWISmtpReply> quit();
Closes the connection to the SMTP server.
RWIOUResult<RWISmtpReply> rcpt(const RWCString& to);
Performs the protocol RCPT action. The RCPT action informs the SMTP server of the recipient (specified by the to argument) of the mail message. A successful reply is normally in the 2XX family.
RWIOUResult<RWISmtpReply> rset();
Performs the protocol RSET action that takes the internal state machine and connection back to the initially connected state. The next action should be a new HELO action. A successful reply is normally in the 2XX family.
RWIOUResult<RWISmtpReply> vrfy(const RWCString& who);
Performs the protocol VRFY action. The VRFY action requests confirmation of the validity of the email recipient, specified as the who argument, without sending a message. A successful reply is normally in the 2XX family if the email address is known by the destination.
©Copyright 2000, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.