Wt  3.7.1
Classes | Public Member Functions | List of all members
Wt::Mail::Message Class Reference

A mail message. More...

#include <Wt/Mail/Message>

Classes

class  Header
 An SMTP message header. More...
 
class  Recipient
 A struct representing a recipient. More...
 

Public Member Functions

 Message ()
 Default constructor. More...
 
void setFrom (const Mailbox &from)
 Sets the sender mailbox.
 
const Mailboxfrom () const
 Returns the sender mailbox. More...
 
void setReplyTo (const Mailbox &replyTo)
 Sets the reply-to mailbox.
 
const MailboxreplyTo () const
 Returns the reply-to mailbox. More...
 
void setSubject (const WString &subject)
 Sets a subject.
 
const WStringsubject () const
 Returns the subject. More...
 
void setDate (const WLocalDateTime &date)
 Sets a date. More...
 
WLocalDateTime date () const
 Returns the date.
 
void setBody (const WString &text)
 Sets the plain text body. More...
 
const WStringbody () const
 Returns the plain text body. More...
 
void addRecipient (RecipientType type, const Mailbox &recipient)
 Adds a recipient. More...
 
const std::vector< Recipient > & recipients () const
 Returns the recipients. More...
 
void setHeader (const std::string &name, const std::string &value)
 Sets a header value. More...
 
void addHeader (const std::string &name, const std::string &value)
 Adds a header value. More...
 
const std::vector< Header > & headers () const
 Returns the headers.
 
const std::string * getHeader (const std::string &name) const
 Returns a header value. More...
 
void addHtmlBody (const WString &text)
 Adds an HTML body. More...
 
const WStringhtmlBody () const
 Returns the HTML body. More...
 
void addAttachment (const std::string &mimeType, const std::string &fileName, std::istream *data)
 Adds an attachment. More...
 
void write (std::ostream &out) const
 Writes the message to the stream. More...
 

Detailed Description

A mail message.

This class represents a MIME-compliant mail message.

The message can have a plain text body and an optional HTML body, which when present is encoded as an MIME multipart/alternative. It is recommended to send the same contents both in a plain text and an HTML variant.

Recipient names, names, and body text may contain unicode text.

See also
Client::send()

Constructor & Destructor Documentation

◆ Message()

Wt::Mail::Message::Message ( )

Default constructor.

Creates an empty message. You need to add at least a sender and a recipient to create a valid email message.

Member Function Documentation

◆ addAttachment()

void Wt::Mail::Message::addAttachment ( const std::string &  mimeType,
const std::string &  fileName,
std::istream *  data 
)

Adds an attachment.

Ownership of the data stream is not transferred; you should keep this object valid until the message has been sent using Client::send() or written using write().

◆ addHeader()

void Wt::Mail::Message::addHeader ( const std::string &  name,
const std::string &  value 
)

Adds a header value.

A header is added, even if a header with the same name already was present.

See also
setHeader()

◆ addHtmlBody()

void Wt::Mail::Message::addHtmlBody ( const WString text)

Adds an HTML body.

The text should be an HTML version of the plain text body.

◆ addRecipient()

void Wt::Mail::Message::addRecipient ( RecipientType  type,
const Mailbox recipient 
)

Adds a recipient.

A mail can have multiple recipients.

◆ body()

const WString& Wt::Mail::Message::body ( ) const

Returns the plain text body.

See also
setBody()

◆ from()

const Mailbox& Wt::Mail::Message::from ( ) const

Returns the sender mailbox.

See also
setFrom()

◆ getHeader()

const std::string * Wt::Mail::Message::getHeader ( const std::string &  name) const

Returns a header value.

Returns 0 if no header with that name is found.

◆ htmlBody()

const WString& Wt::Mail::Message::htmlBody ( ) const

Returns the HTML body.

See also
setHtmlBody()

◆ recipients()

const std::vector<Recipient>& Wt::Mail::Message::recipients ( ) const

Returns the recipients.

See also
addRecipient()

◆ replyTo()

const Mailbox& Wt::Mail::Message::replyTo ( ) const

Returns the reply-to mailbox.

See also
setReplyTo()

◆ setBody()

void Wt::Mail::Message::setBody ( const WString text)

Sets the plain text body.

This is the plain text mail contents.

See also
addHtmlBody()

◆ setDate()

void Wt::Mail::Message::setDate ( const WLocalDateTime date)

Sets a date.

According to RFC 2822, the date should express local time.

◆ setHeader()

void Wt::Mail::Message::setHeader ( const std::string &  name,
const std::string &  value 
)

Sets a header value.

If a header with that value was already defined, it is replaced with the new value. Otherwise, the header is added.

See also
addHeader()

◆ subject()

const WString& Wt::Mail::Message::subject ( ) const

Returns the subject.

See also
setSubject()

◆ write()

void Wt::Mail::Message::write ( std::ostream &  out) const

Writes the message to the stream.

This writes the message as a MIME 1.0 message to the output stream.


Generated on Tue Dec 15 2020 for the C++ Web Toolkit (Wt) by doxygen 1.8.13