in C++ :

#include <procbuf.h> //declaration for procbuf class.

void main()
//'procbuf' class is a child of the 'streambuf' class, it is used to read/write
//from/to a pipe.
    procbuf mailer("/usr/sbin/sendmail -oi -t", ios::out);
//the 'form' method (defined in the 'streambuf' class is similar to the stdio.h
//'printf' fn.
    mailer.form("To: goofy\n");
    mailer.form("From: riko\n");
    mailer.form("Subject: testo2\n\n");
    mailer.form("tito fito C++ O");

in C :

#include <stdio.h>

void main()
    FILE *out;
/* the 'popen' fn. executes 'sendmail' as a subprocess &  creates a pipe that
subprocess, now one can write/read to the 'out' stream using 'fprintf'/'fscanf'
    out = popen("/usr/sbin/sendmail -oi -t", "w");
    fprintf(out, "To: goofy\n");
    fprintf(out, "From: riko\n");
    fprintf(out, "Subject: testo\n\n");
    fprintf(out, "test message\n");

//  dev/iostream.html#SEC31
//  /dev/libc.html#SEC117

This code has been written using lpe & was converted to html using code2html.