SMTP client class. More...
#include <smtp.h>

Public Member Functions | |
| smtpsocket (void) | |
| ~smtpsocket (void) | |
| void | setsmtphost (const string &hostname, int port=25) |
| void | setsender (const string &address, const string &name) |
| void | setsender (const string &address) |
| bool | sendmessage (const value &rcptto, const string &subject, const string &body, const string &mailfrom, const string &contenttype) |
| bool | sendmessage (const value &rcptto, const string &subject, const string &body, const string &mailfrom) |
| bool | sendmessage (const value &rcptto, const string &subject, const string &body) |
| void | setheader (const statstring &name, const string &val) |
| const string & | error (void) |
| int | errorcode (void) |
| bool | dosmtp (const value &rcptto, const string &body) |
Protected Attributes | |
| string | smtphost |
| int | smtpport |
| string | sender |
| string | sendername |
| string | hostname |
| value | headers |
| string | err |
| int | erno |
SMTP client class.
Implements the SMTP protocol for sending email through a server.
| smtpsocket::smtpsocket | ( | void | ) |
Constructor.
Defaults the SMTP connection to localhost and the sender address to the current username with the system hostname as the email domain.
References erno, systemclass::userdbFunctions::getpwuid(), systemclass::userdbFunctions::getuid(), systemclass::netFunctions::hostname(), hostname, systemclass::net, setsender(), setsmtphost(), and systemclass::userdb.

| smtpsocket::~smtpsocket | ( | void | ) |
Destructor.
Boring, since it doesn't involve any acts of blowing things up.
Act on an SMTP transaction.
Assumes all proper headers and properties have been set.
References file::close(), tcpsocket::connect(), value::count(), erno, err, value::exists(), file::gets(), headers, hostname, file::puts(), strutil::regexp(), sender, sendername, smtphost, smtpport, string::strcat(), value::sval(), and string::toint().
Referenced by sendmessage().

Dispatch an SMTP message.
| rcptto | Recipient(s). Can be either an array of one or more string objects containing recipient addresses or a string object containing a single email address. | |
| subject | The email subject. | |
| body | The email body. |
References dosmtp(), and setheader().

| bool smtpsocket::sendmessage | ( | const value & | rcptto, | |
| const string & | subject, | |||
| const string & | body, | |||
| const string & | mailfrom | |||
| ) |
Dispatch an SMTP message.
| rcptto | Recipient(s). Can be either an array of one or more string objects containing recipient addresses or a string object containing a single email address. | |
| subject | The email subject. | |
| body | The email body. | |
| mailfrom | The sender address. |
References dosmtp(), setheader(), and setsender().

| bool smtpsocket::sendmessage | ( | const value & | rcptto, | |
| const string & | subject, | |||
| const string & | body, | |||
| const string & | mailfrom, | |||
| const string & | contenttype | |||
| ) |
Dispatch an SMTP message.
| rcptto | Recipient(s). Can be either an array of one or more string objects containing recipient addresses or a string object containing a single email address. | |
| subject | The email subject. | |
| body | The email body. | |
| mailfrom | The sender address. | |
| contenttype | The body content-type. |
References dosmtp(), setheader(), and setsender().

| void smtpsocket::setheader | ( | const statstring & | name, | |
| const string & | val | |||
| ) |
Set an outgoing mail header.
| name | The header name. | |
| val | The header value. |
References headers.
Referenced by sendmessage().
| void smtpsocket::setsender | ( | const string & | address | ) |
Sets the email sender.
Expects an email address either in the raw form or the RFC name+email form:
The first form will default to a name of "Mail System" if the sender address is used in the From header.
References string::chomp(), string::cropat(), sender, sendername, strutil::splitquoted(), and string::strchr().

Sets the email sender.
If no separate From header is supplied this will also be supplied as the From-address.
| address | The email address. | |
| name | The sender's name. |
References sender, and sendername.
Referenced by sendmessage(), and smtpsocket().
| void smtpsocket::setsmtphost | ( | const string & | hostname, | |
| int | port = 25 | |||
| ) |
Sets the address of the SMTP server.
| hostname | SMTP hostname. | |
| port | SMTP tcp port defaults to 25. |
References smtphost, and smtpport.
Referenced by smtpsocket().
1.6.1