Sending Messages

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

jmail_send.png

jmail_sendparams.png

Operations

sendMessage

Parameter Types Direction Description
connection (25.2) JavaMail Library Reference#Connection in Specify the Connection object defining the mail server connection parameters to use (see Mail Server Connection).
mail

(25.2) JavaMail Library Reference#Mail

in Prepare 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).

Parameter Types Direction Description Allowed Values / Example
connection (25.2) JavaMail Library Reference#Connection in Specify the Connection object defining the mail server connection parameters to use (see Mail Server Connection).

mail

(25.2) JavaMail Library Reference#Mail

in Prepare a mail object to send.

encryptionMode

String

in Specify 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 Name Type Description
sender String

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.

toRecipients Array of String Provide an array of TO recipient's email addresses.
ccRecipients Array of String Provide an array of CC recipient's email addresses.
bccRecipients Array of String Provide an array of BCC recipient's email addresses.
subject String Provide the email subject.
attachments Array of (25.2) JavaMail Library Reference#Attachment Provide an array of email attachments.
plainTextContent String

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.

htmlTextContent String

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 Name Type Description Possible Values
binary Boolean Indicates whether binaryContent or stringContent is used. true Attachment contents canl be found in, or shall be taken from, binaryContent.
false Attachment contents can/shall be found in, or shall be taken from, stringContent.
filename String The 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).

binaryContent Blob

Contains the binary content.

any Blob

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

Contains the non-binary content.

any String

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



mimeType String Contains 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.

contentId String The 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">
inline Boolean Controls whether the attachment is flagged with the corresponding content disposition tag. true Attachment is flagged, and will be displayed inline within a HTML message.
false Attachment is not flagged.

Related Pages: