Example 26 sends a mail message using the SMTP agent class.
Servers and files shown in the code might not exist and are included as examples only.
try { RWSmtpAgent agent("SMTP_mail_server"); // 1 RWSocketPortal sPortal = agent.send("From", "To"); // 2 RWCString mailContent; . . . // Construct the mailContent . . . sPortal.sendAtLeast(mailContent); // 3 bool dataClosed = agent.dataClose(); // 4 } catch (const RWxmsg& msg) { cout << "ERROR: " << msg.why() << endl; } |
//1 | Constructs an RWSmtpAgent object that connects to an SMTP mail server. |
//2 | Opens a data connection with the SMTP server. The method returns an RWTIOUResult 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 RWTIOUResult with a redeemable bool. By assigning the result of the method to the bool object dataClosed, the execution thread is blocked until the actual result becomes available. This is one way of redeeming an RWTIOUResult object. The SMTP protocol requires that the dataClose() method be called for each data transfer session. |
This example demonstrates one method of redeeming an RWTIOUResult object. For other methods, see Section 2.4, "Multithreading and IOUs," and Section 4.7, "File Retrieval: Using the FTP Agent (Part II)."
Copyright © Rogue Wave Software, Inc. All Rights Reserved.
The Rogue Wave name and logo, and SourcePro, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.