Wt: Wt::Mail::Client Class Reference

Wt 3.3.0

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes

- Class List
- Class Hierarchy
- Class Members

Public Member Functions
Wt::Mail::Client Class Reference
SMTP client library (Wt::Mail)

An SMTP mail client. More...

`#include <Wt/Mail/Client>`

List of all members.

## Public Member Functions
| Client (const std::string &selfHost=std::string())
| Constructor.
| ~Client ()
| Destructor.
bool | connect ()
| Connects to the default SMTP server.
bool | connect (const std::string &smtpHost, int smtpPort=25)
| Connects to a given STMP server and port.
void | disconnect ()
| Disconnects the client from the SMTP server.
void | send (const Message &message)
| Sends a message.

## Detailed Description

An SMTP mail client.

The SMTP client can send one or more mail messages to an SMTP host.

     #include <Wt/Mail/Client>
     #include <Wt/Mail/Message>

     Mail::Message message;
     message.setFrom(Mail::Mailbox("kudos@corp.org", "Kudos Dukos");
     message.addRecipient(Mail::To, Mail::Mailbox("koen@emweb.be", "Koen Deforche");
     message.setSubject("Hey there, koen!");
     message.setBody("That mail client seems to be working.");
     message.addHtmlBody ("<p>"
          "<a href=\"http://www.webtoolkit.eu/wt\">That mail client</a>"
          " seems to be working just great!</p>");

     Mail::Client client;
     client.connect("localhost");
     client.send(message);

Only the bare essentials of the SMTP protocol are current implemented, although the Message itself supports proper unicode handling.

Note:
  Currently only a plain-text SMTP protocol is supported. SSL transport will be added in the future.
  Currently the client sends an email synchronously, and thus a slow connection to the SMTP server may block the current thread. We plan to change this in the future. It is thus beneficial to connect to a local SMTP daemon to minimize this deficiency.

## Constructor & Destructor Documentation

Wt::Mail::Client::Client | ( | const std::string & | selfHost = `std::string()` | ) |

Constructor.

The `selfHost` is how the mail client will identify itself to the mail server, in the EHLO command.

If not defined, the "smtp-self-host" configuration property is used, and if that property is not defined, it defaults to "localhost".

Wt::Mail::Client::~Client | ( |  | ) |

Destructor.

If the client is still connected, this disconnects the client.

## Member Function Documentation

bool Wt::Mail::Client::connect | ( |  | ) |

Connects to the default SMTP server.

This connects to the SMTP server defined by the "smtp-host" property, on port defined by the "smtp-port" property. If these properties are not set, "localhost" and 25 are used as defaults respectively.

Returns whether the connection could be established and the SMTP hand-shake was successful.

bool Wt::Mail::Client::connect | ( | const std::string & | smtpHost,
|  | int | smtpPort = `25`
| ) |  |

Connects to a given STMP server and port.

Returns whether the connection could be established and the SMTP hand-shake was successful.

void Wt::Mail::Client::send | ( | const Message & | message | ) |

Sends a message.

The client must be connected before messages can be sent.

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator