PREV UP NEXT C++ socket classes for OS/2

Chapter 12: SMTP Class

The smtp class, which is derived from protocol class, implements RFC 821. It can be used only as a client. Server function is not yet implemented.

smtp uses smtp::smtpbuf as its underlying stream buffer. Also, like the protocol class, smtp is a smart pointer class for it is smtp::smtpbuf.

In what follows,

smtp s (io)
constructs an smtp client, s. Any response the client gets from the server is sent to the ostream, io.
sb.get_response ()
gets the server response and sends it to io of the smtpbuf.
sb.send_cmd (str0, str1, str2)
concatenates strings str0, str1, and str2 and sends the concatenated string to the server before getting its response.
sb.send_buf (buf, buflen)
sends the contents of the buf to the server.
sb.helo ()
sb.help (str)
sb.quit ()
sb.turn ()
sb.rset ()
sb.noop ()
sb.data ()
sb.vrfy (str)
sb.expn (str)
implements the respective smtp commands. See RFC 821 for the meaning of each.
sb.mail (str)
sends the mail command to the server. str is the the reverse path or the FROM address.
sb.rcpt (str)
sends the recipient command to the server. str is the forward path or the TO address.
sb.data (buf, buflen)
sends the contents of the buffer, buf as the mail data to the recipient previously established through smtpbuf::rcpt() calls.
sb.data (filename)
sends the contents of the file, filename as the mail data to the recipient previously established through smtpbuf::rcpt() calls.

12.0.1: tcsmtp.C


// smtp client.

// The president sends a message to gs4t@virginia.edu.

#include <smtp.h>

#include <stdio.h>

#include <pwd.h>

#include <unistd.h>



int main ()

{

  bsmtp client (&cout);



  // establish connection

  client->connect ("fulton.seas.virginia.edu");

  client->helo ();



  // get help

  client->help ();



  // setup the FROM address

  client->mail ("president@whitehouse.gov");



  // setup the TO address

  client->rcpt ("gs4t@virginia.edu");



  // send the message

  client->data ();

  client << "Hi Sekar, I appoint you as the director of NASA\r\n" << flush;

  client << "    -Bill, Hill, and Chel\r\n" << flush;

  cout << client; // get the server response.



  // finally quit

  client->quit ();



  return 0;

}