This example program sends an e-mail message using the SMTP agent class.
Here is a portion of code followed by comments explaining key lines.
try { RWISmtpAgent agent("SMTP_mail_server"); // 1 RWSocketPortal sPortal = agent.send("From", "To"); // 2 RWCString mailContent; . . . // Construct the mailContent . . . sPortal.sendAtLeast(mailContent); // 3 RWBoolean dataClosed = agent.dataClose(); // 4 } catch (const RWxmsg& msg) { cout << "ERROR: " << msg.why() << endl; }
//1 | Constructs an RWISmtpAgent object that connects to an SMTP mail server. |
//2 | Opens a data connection with the SMTP server. The method returns an RWIOUResult with a redeemable RWSocketPortal, which is immediately redeemed. The sPortal is then used to complete the mail-body portion of the protocol transfer. |
//3 | Uses the sPortal to send the mail content. |
//4 | Writes the mail-body termination sequence <period><carriage return><new line>, which indicates the end of the mail message. The dataClose() method returns an RWIOUResult with a redeemable RWBoolean. By assigning the result of the method to the RWBoolean object dataClosed, the execution thread is blocked until the actual result becomes available. This is one way of redeeming an RWIOUResult object. Also note that the SMTP protocol requires the dataClose() method be called for each data transfer session. |
This example demonstrates one method of redeeming an RWIOUResult object. For other methods, please refer to Chapter 19 and Section 20.4. The application determines which way needs to apply.
©Copyright 2000, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.