Skip to main content
Skip table of contents

Sending Messages

Sending messages requires you to assemble an instance of Mail and feeding it to the sendMessage() operation.

Operations

sendMessage

ParameterTypesDirectionDescription
connection(24.1) JavaMail Library Reference#ConnectioninSpecify the Connection object defining the mail server connection parameters to use (see Mail Server Connection).
mail

(24.1) JavaMail Library Reference#Mail

inPrepare a mail object to send.

sendPgpMessage

Requires IPgpKeyProvider Implementation

For PGP encryption to work, be sure to register your implementation of IPgpKeyProvider (see Keys and Certificates).

ParameterTypesDirectionDescriptionAllowed Values / Example
connection(24.1) JavaMail Library Reference#ConnectioninSpecify the Connection object defining the mail server connection parameters to use (see Mail Server Connection).

mail

(24.1) JavaMail Library Reference#Mail

inPrepare a mail object to send.

encryptionMode

String

inSpecify one of the encryption modes.

PREFER

Apply encryption when PGP keys can be retrieved (see Keys and Certificates), otherwise do not apply any encryption.

ENFORCE

Apply encryption when PGP keys can be retrieved, otherwise throw an exception.

NONE

Do not apply any encryption (default, same behavior as sendMessage()).

Types

Mail

Attribute NameTypeDescription
senderString

Provide the email address of the sender.

Sending Messages

Some email servers (especially Exchange servers) require this to be the address of the user specified in the connection. They will raise an imposter exception if this is not the case.

toRecipientsArray of StringProvide an array of TO recipient's email addresses.
ccRecipientsArray of StringProvide an array of CC recipient's email addresses.
bccRecipientsArray of StringProvide an array of BCC recipient's email addresses.
subjectStringProvide the email subject.
attachmentsArray of (24.1) JavaMail Library Reference#AttachmentProvide an array of email attachments.
plainTextContentString

Provide a plain text message if applicable.

Mime messages allow for multipart/alternative parts. If you specify both plainTextContent and htmlTextContent, the JavaMail library will send both as a multipart/alternative when connecting via SMTP.
EWS does not allow this. So, when sending through Exchange, the library will pick the HTML content if provided.

htmlTextContentString

Provide an HTML message if applicable.

Mime messages allow for multipart/alternative parts. If you specify both plainTextContent and htmlTextContent, the JavaMail library will send both as a multipart/alternative when connecting via SMTP.
EWS does not allow this. So, when sending through Exchange, the library will pick the HTML content if provided.

Attachment

Inline Images

Adding inline images to HTML emails is an art form. Be prepared to see different results depending on the client application receiving your message. Make sure to test your HTML code thoroughly to get good results.
Also, sending large images inline is considered bad style as it blows up message size considerably and could be replaced with links to online locations of the image (e.g. a CDN or publicly accessible web server).

Attribute NameTypeDescriptionPossible Values
binaryBooleanIndicates whether binaryContent or stringContent is used.trueAttachment contents canl be found in, or shall be taken from, binaryContent.
falseAttachment contents can/shall be found in, or shall be taken from, stringContent.
filenameStringThe filename of the attachment.
  • can be NULL

Sending Messages

This is the name of the file as you want it to appear at the recipient's side, or vice versa.

Do not provide a local file name here and expect the library to load the attachment from that file. Use the File System Adapter instead, and provide the attachment as binary blob content (see binaryContent).

binaryContentBlob

Contains the binary content.

any Blob

Either one of binaryContent or stringContent is provided, depending on binary.
stringContentString

Contains the non-binary content.

any String

Either one of binaryContent or stringContent is provided, depending on binary.



mimeTypeStringContains the mime type (content type) of the attachment.

any valid MIME content-type, e.g. text/plain, image/png, application/octet-stream etc.

mimeType is unreliable upon receiving emails, i.e. can be NULL. Especially when reading from Exchange servers using exchange or office365 connections.

contentIdStringThe content id of the attachment, a unique id across all attachments of the same message.When set to e.g. myUniqueId, you can refer to this attachment from HTML message content like <img src="cid:myUniqueId">
inlineBooleanControls whether the attachment is flagged with the corresponding content disposition tag.trueAttachment is flagged, and will be displayed inline within a HTML message.
falseAttachment is not flagged.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.