The OpenD Programming Language

EmailMessage

For OUTGOING email

More...

Constructors

this
this(string linesep)

Members

Functions

addAttachment
void addAttachment(string mimeType, string filename, void[] content, string id)

The filename is what is shown to the user, not the file on your sending computer. It should NOT have a path in it.

addInlineImage
void addInlineImage(string id, string mimeType, string filename, void[] content)

in the html, use img src="cid:ID_GIVEN_HERE"

addRecipient
void addRecipient(string name, string email, ToType how)
addRecipient
void addRecipient(string who, ToType how)
htmlBody
string htmlBody()

Gets the current html body, if any.

send
void send(RelayInfo mailServer)

Sends via a given SMTP relay

setHeader
void setHeader(string name, string value, string file, size_t line)

Adds a custom header to the message. The header name should not include a colon and must not duplicate a header set elsewhere in the class; for example, do not use this to set To, and instead use the to field.

setHtmlBody
void setHtmlBody(string html)

Sets the HTML body to the mail, which can support rich text, inline images (see addInlineImage), etc.

setTextBody
void setTextBody(string text)

Sets the plain text body of the email. You can also separately call setHtmlBody to set a HTML body.

textBody
string textBody()
void textBody(string text)

Gets and sets the current text body.

toString
string toString()

Returns the MIME formatted email string, including encoded attachments

Variables

bcc
RecipientList bcc;
cc
RecipientList cc;

Recipients of the message. You can use operator ~= to add people to this list, or you can also use addRecipient to achieve the same result.

from
EmailRecipient from;

Represents the From: and Reply-To: header values in the email.

inReplyTo
string inReplyTo;

The In-Reply-to: header value. This should be set to the same value as the Message-ID header from the message you're replying to.

linesep
string linesep;

If you use the send method with an SMTP server, you don't want to change this. While RFC 2045 mandates CRLF as a lineseperator, there are some edge-cases where this won't work. When passing the E-Mail string to a unix program which handles communication with the SMTP server, some (i.e. qmail) expect the system lineseperator (LF) instead. Notably, the google mail REST API will choke on CRLF lineseps and produce strange emails (as of 2024).

replyTo
EmailRecipient replyTo;

Represents the From: and Reply-To: header values in the email.

subject
string subject;

The Subject: header value in the email.

to
RecipientList to;

Recipients of the message. You can use operator ~= to add people to this list, or you can also use addRecipient to achieve the same result.

Detailed Description

To use:

auto message = new EmailMessage();
message.to ~= "someuser@example.com";
message.from = "youremail@example.com";
message.subject = "My Subject";
message.setTextBody("hi there");
//message.toString(); // get string to send externally
message.send(); // send via some relay
// may also set replyTo, etc

Meta

History

This class got an API overhaul on May 13, 2024. Some undocumented members were removed, and some public members got changed (albeit in a mostly compatible way).