7.5 Mail Sender: Using the SMTP Agent
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.
Example 26 – Using the SMTP agent to send a mail message
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;
}
The SMTP protocol requires that the dataClose() method be called for each data transfer session.