Codeunit "Email Message"
Codeunit to create and manage email messages.
Properties
| Name | Value |
|---|---|
| Access | Public |
Methods
Create
Creates the email with recipients, subject, and body.
procedure Create(ToRecipients: Text, Subject: Text, Body: Text)
Parameters
| Name | Type | Description |
|---|---|---|
| ToRecipients | Text |
The recipient(s) of the email. A string containing the email addresses of the recipients separated by semicolon. |
| Subject | Text |
The subject of the email. |
| Body | Text |
Raw text that will be used as body of the email. |
Create
Creates the email with recipients, subject, and body.
procedure Create(ToRecipients: Text, Subject: Text, Body: Text, HtmlFormatted: Boolean)
Parameters
| Name | Type | Description |
|---|---|---|
| ToRecipients | Text |
The recipient(s) of the email. A string containing the email addresses of the recipients separated by semicolon. |
| Subject | Text |
The subject of the email. |
| Body | Text |
The body of the email. |
| HtmlFormatted | Boolean |
Whether the body is HTML formatted. |
Create
Creates the email with recipients, subject, and body.
procedure Create(ToRecipients: Text, Subject: Text, Body: Text, HtmlFormatted: Boolean, Sanitize: Boolean)
Parameters
| Name | Type | Description |
|---|---|---|
| ToRecipients | Text |
The recipient(s) of the email. A string containing the email addresses of the recipients separated by semicolon. |
| Subject | Text |
The subject of the email. |
| Body | Text |
The body of the email. |
| HtmlFormatted | Boolean |
Whether the body is HTML formatted. |
| Sanitize | Boolean |
If the body is of HTML formatting, most of it will be sanitized. Keeping only tags and no styling. |
Remarks
Sanitize is only applicable if the body is HTML formatted. It also helps prevent potential email messages from hiding images and text from the user.
Create
Creates the email with recipients, subject, and body.
procedure Create(ToRecipients: List of [Text], Subject: Text, Body: Text, HtmlFormatted: Boolean)
Parameters
| Name | Type | Description |
|---|---|---|
| ToRecipients | List of [Text] |
The recipient(s) of the email. A list of email addresses the email will be send directly to. |
| Subject | Text |
The subject of the email. |
| Body | Text |
The body of the email |
| HtmlFormatted | Boolean |
Whether the body is HTML formatted |
Create
Creates the email with recipients, subject, and body.
procedure Create(ToRecipients: List of [Text], Subject: Text, Body: Text, HtmlFormatted: Boolean, CCRecipients: List of [Text], BCCRecipients: List of [Text])
Parameters
| Name | Type | Description |
|---|---|---|
| ToRecipients | List of [Text] |
The recipient(s) of the email. A list of email addresses the email will be send directly to. |
| Subject | Text |
The subject of the email. |
| Body | Text |
The body of the email. |
| HtmlFormatted | Boolean |
Whether the body is HTML formatted. |
| CCRecipients | List of [Text] |
The CC recipient(s) of the email. A list of email addresses that will be listed as CC. |
| BCCRecipients | List of [Text] |
TThe BCC recipient(s) of the email. A list of email addresses that will be listed as BCC. |
CreateReply
Creates the email reply with recipients, subject, and body.
procedure CreateReply(ToRecipients: Text, Subject: Text, Body: Text, HtmlFormatted: Boolean, ExternalId: Text)
Parameters
| Name | Type | Description |
|---|---|---|
| ToRecipients | Text |
The recipient(s) of the email. A string containing the email addresses of the recipients separated by semicolon. |
| Subject | Text |
The subject of the email. |
| Body | Text |
The body of the email. |
| HtmlFormatted | Boolean |
Whether the body is HTML formatted. |
| ExternalId | Text |
The external message id to reply to. |
CreateReply
Creates the email reply with recipients, subject, and body.
procedure CreateReply(ToRecipients: List of [Text], Subject: Text, Body: Text, HtmlFormatted: Boolean, ExternalId: Text)
Parameters
| Name | Type | Description |
|---|---|---|
| ToRecipients | List of [Text] |
The recipient(s) of the email. A list of email addresses the email will be send directly to. |
| Subject | Text |
The subject of the email. |
| Body | Text |
The body of the email. |
| HtmlFormatted | Boolean |
Whether the body is HTML formatted. |
| ExternalId | Text |
The external message id to reply to. |
CreateReply
Creates the email reply with recipients, subject, and body.
procedure CreateReply(ToRecipients: List of [Text], Subject: Text, Body: Text, HtmlFormatted: Boolean, ExternalId: Text, CCRecipients: List of [Text], BCCRecipients: List of [Text])
Parameters
| Name | Type | Description |
|---|---|---|
| ToRecipients | List of [Text] |
The recipient(s) of the email. A list of email addresses the email will be send directly to. |
| Subject | Text |
The subject of the email. |
| Body | Text |
The body of the email. |
| HtmlFormatted | Boolean |
Whether the body is HTML formatted. |
| ExternalId | Text |
The external message id to reply to. |
| CCRecipients | List of [Text] |
The CC recipient(s) of the email. A list of email addresses that will be listed as CC. |
| BCCRecipients | List of [Text] |
TThe BCC recipient(s) of the email. A list of email addresses that will be listed as BCC. |
CreateReplyAll
Creates the email replying to all existing recipents on the mail thread, subject, and body.
procedure CreateReplyAll(Subject: Text, Body: Text, HtmlFormatted: Boolean, ExternalId: Text)
Parameters
| Name | Type | Description |
|---|---|---|
| Subject | Text |
The subject of the email. |
| Body | Text |
The body of the email. |
| HtmlFormatted | Boolean |
Whether the body is HTML formatted. |
| ExternalId | Text |
The external message id to reply to. |
Get
Gets the email message with the given ID.
procedure Get(MessageId: Guid): Boolean
Parameters
| Name | Type | Description |
|---|---|---|
| MessageId | Guid |
The ID of the email message to get. |
Returns
| Type | Description |
|---|---|
| Boolean |
True if the email was found; otherwise - false. |
DeleteOrphanedMessages
Deletes messages that does not have a reference from either the email outbox nor sent email. This functionality is only needed if email messages have been created without any email outbox or sent email referencing it, otherwise they will be cleaned up automatically.
procedure DeleteOrphanedMessages(StartMessageId: Guid, MessagesToIterate: Integer): Guid
Parameters
| Name | Type | Description |
|---|---|---|
| StartMessageId | Guid |
The email message id to start from. Using empty guid will start from the beginning. |
| MessagesToIterate | Integer |
Number of email messages to loop over. |
Returns
| Type | Description |
|---|---|
| Guid |
The next email message id to be checked. Returns empty guid if there are no more messages. |
DeleteEmailRecipientsIfOrphaned
Deletes email recipients that do not have a reference from email message. This functionality is only needed if email recipients have been created without any email message referencing it, otherwise they will be cleaned up automatically.
procedure DeleteEmailRecipientsIfOrphaned(StartMessageId: Guid, MessagesToIterate: Integer): Guid
Parameters
| Name | Type | Description |
|---|---|---|
| StartMessageId | Guid |
The email message id to start from. Using empty guid will start from the beginning. |
| MessagesToIterate | Integer |
Number of email messages to loop over. |
Returns
| Type | Description |
|---|---|
| Guid |
The next email message id to be checked. Returns empty guid if there are no more messages. |
Remarks
Only the recipients that are not referenced by any email message will be deleted.
GetBody
Gets the body of the email message.
procedure GetBody(): Text
Returns
| Type | Description |
|---|---|
| Text |
The body of the email. |
SetBody
Sets the body of the email message.
procedure SetBody(Body: Text)
Parameters
| Name | Type | Description |
|---|---|---|
| Body | Text |
The body to set to the email message. |
AppendToBody
Appends to the body of the email message.
The value to append to the body of the email message.procedure AppendToBody(Value: Text)
Parameters
| Name | Type | Description |
|---|---|---|
| Value | Text |
GetExternalId
procedure GetExternalId(): Text[2048]
Returns
| Type | Description |
|---|---|
| Text[2048] |
GetSubject
Gets the subject of the email message.
procedure GetSubject(): Text[2048]
Returns
| Type | Description |
|---|---|
| Text[2048] |
The subject of the email. |
SetSubject
Sets the subject of the email message.
procedure SetSubject(Subject: Text)
Parameters
| Name | Type | Description |
|---|---|---|
| Subject | Text |
The subject to set to the email message. |
IsBodyHTMLFormatted
Checks if the email body is formatted in HTML.
procedure IsBodyHTMLFormatted(): Boolean
Returns
| Type | Description |
|---|---|
| Boolean |
True if the email body is formatted in HTML; otherwise - false. |
SetBodyHTMLFormatted
Sets whether the email body is formatted in HTML.
True if the email body is formatted in HTML; otherwise - false.procedure SetBodyHTMLFormatted(Value: Boolean)
Parameters
| Name | Type | Description |
|---|---|---|
| Value | Boolean |
GetId
Gets the ID of the email message.
procedure GetId(): Guid
Returns
| Type | Description |
|---|---|
| Guid |
The ID of the email. |
GetRecipients
Gets the recipents of a certain type of the email message.
procedure GetRecipients(RecipientType: Enum "Email Recipient Type", var Recipients: List of [Text])
Parameters
| Name | Type | Description |
|---|---|---|
| RecipientType | Enum System.Email."Email Recipient Type" |
Specifies the type of the recipients. |
| Recipients | List of [Text] |
Out parameter filled with the recipients' email addresses. |
SetRecipients
Sets the recipents of a certain type of the email message.
procedure SetRecipients(RecipientType: Enum "Email Recipient Type", Recipients: Text)
Parameters
| Name | Type | Description |
|---|---|---|
| RecipientType | Enum System.Email."Email Recipient Type" |
Specifies the type of the recipients. |
| Recipients | Text |
Specifies the list of the recipients' email addresses as a semicolon (;) separated list. |
SetRecipients
Sets the recipents of a certain type of the email message.
procedure SetRecipients(RecipientType: Enum "Email Recipient Type", Recipients: List of [Text])
Parameters
| Name | Type | Description |
|---|---|---|
| RecipientType | Enum System.Email."Email Recipient Type" |
Specifies the type of the recipients. |
| Recipients | List of [Text] |
Specifies the list of the recipients' email addresses. |
AddRecipient
Adds a recipient of a certain type to the email message.
procedure AddRecipient(RecipientType: Enum "Email Recipient Type", Recipient: Text)
Parameters
| Name | Type | Description |
|---|---|---|
| RecipientType | Enum System.Email."Email Recipient Type" |
Specifies the type of the recipient. |
| Recipient | Text |
Specifies the recipient's email address. |
AddAttachment
Adds a file attachment to the email message.
procedure AddAttachment(AttachmentName: Text[250], ContentType: Text[250], AttachmentBase64: Text)
Parameters
| Name | Type | Description |
|---|---|---|
| AttachmentName | Text[250] |
The name of the file attachment. |
| ContentType | Text[250] |
The Content Type of the file attachment. |
| AttachmentBase64 | Text |
The Base64 text representation of the attachment. |
AddAttachment
Adds a file attachment to the email message.
procedure AddAttachment(AttachmentName: Text[250], ContentType: Text[250], AttachmentInStream: InStream)
Parameters
| Name | Type | Description |
|---|---|---|
| AttachmentName | Text[250] |
The name of the file attachment. |
| ContentType | Text[250] |
The Content Type of the file attachment. |
| AttachmentInStream | InStream |
The instream of the attachment. |
AddAttachment
Adds a file attachment to the email message.
procedure AddAttachment(AttachmentName: Text[250], ContentType: Text[250], InLine: Boolean, ContentId: Text[40], AttachmentInStream: InStream)
Parameters
| Name | Type | Description |
|---|---|---|
| AttachmentName | Text[250] |
The name of the file attachment. |
| ContentType | Text[250] |
The Content Type of the file attachment. |
| InLine | Boolean |
Specifies whether the attachment is inline. |
| ContentId | Text[40] |
The Content ID of the file attachment. |
| AttachmentInStream | InStream |
The instream of the attachment. |
AddAttachmentFromScenario
Adds attachments from scenario to the email message.
procedure AddAttachmentFromScenario(var EmailAttachments: Record "Email Attachments" temporary)
Parameters
| Name | Type | Description |
|---|---|---|
| EmailAttachments | Table System.Email."Email Attachments" |
The reference to the email attachments |
Attachments_DeleteContent
Deletes the contents of the currently selected attachment.
procedure Attachments_DeleteContent(): Boolean
Returns
| Type | Description |
|---|---|
| Boolean |
Returns true if contents was successfully deleted, otherwise false. |
Attachments_DeleteContent
Deletes the contents of the currently selected attachment.
procedure Attachments_DeleteContent(BypassSentCheck: Boolean): Boolean
Parameters
| Name | Type | Description |
|---|---|---|
| BypassSentCheck | Boolean |
If true, the attachment content will be deleted even if the email message has been sent. |
Returns
| Type | Description |
|---|---|
| Boolean |
Returns true if contents was successfully deleted, otherwise false. |
Attachments_Delete
Deletes the currently selected attachment.
procedure Attachments_Delete(): Boolean
Returns
| Type | Description |
|---|---|
| Boolean |
Returns true if attachment was successfully deleted, otherwise false. |
Attachments_Delete
Deletes the currently selected attachment.
procedure Attachments_Delete(BypassSentCheck: Boolean): Boolean
Parameters
| Name | Type | Description |
|---|---|---|
| BypassSentCheck | Boolean |
If true, the attachment will be deleted even if the email message has been sent. |
Returns
| Type | Description |
|---|---|
| Boolean |
Returns true if attachment was successfully deleted, otherwise false. |
Attachments_First
Finds the first attachment of the email message.
procedure Attachments_First(): Boolean
Returns
| Type | Description |
|---|---|
| Boolean |
True if there is any attachment; otherwise - false. |
Attachments_Next
Finds the next attachment of the email message.
procedure Attachments_Next(): Integer
Returns
| Type | Description |
|---|---|
| Integer |
The ID of the next attachment if it was found; otherwise - 0. |
Attachments_GetId
Gets the Id of the current attachment
procedure Attachments_GetId(): BigInteger
Returns
| Type | Description |
|---|---|
| BigInteger |
The ID of the current attachment. |
Attachments_GetName
Gets the name of the current attachment.
procedure Attachments_GetName(): Text[250]
Returns
| Type | Description |
|---|---|
| Text[250] |
The name of the current attachment. |
Attachments_GetContent
Gets the content of the current attachment.
procedure Attachments_GetContent(var AttachmentInStream: InStream)
Parameters
| Name | Type | Description |
|---|---|---|
| AttachmentInStream | InStream |
Out parameter with the content of the current attachment. |
Attachments_GetContentBase64
Gets the content of the current attachment in Base64 encoding.
procedure Attachments_GetContentBase64(): Text
Returns
| Type | Description |
|---|---|
| Text |
The content of the current attachment in Base64 encoding. |
Attachments_GetContentType
Gets the content type of the current attachment.
procedure Attachments_GetContentType(): Text[250]
Returns
| Type | Description |
|---|---|
| Text[250] |
The content type of the current attachment. |
Attachments_GetContentId
Gets the content ID of the current attachment.
procedure Attachments_GetContentId(): Text[40]
Returns
| Type | Description |
|---|---|
| Text[40] |
The content ID of the current attachment. |
Remarks
This value is filled only if the attachment is inline the email body.
Attachments_GetLength
Gets the content length of the current attachment.
procedure Attachments_GetLength(): Integer
Returns
| Type | Description |
|---|---|
| Integer |
The content length of the current attachment. |
Attachments_IsInline
Checks if the attachment is inline the message body.
procedure Attachments_IsInline(): Boolean
Returns
| Type | Description |
|---|---|
| Boolean |
True if the attachment is inline the message body; otherwise - false. |
GetRelatedAttachments
Gets the related attachments.
procedure GetRelatedAttachments(var EmailRelatedAttachments: Record "Email Related Attachment" temporary): Boolean
Parameters
| Name | Type | Description |
|---|---|---|
| EmailRelatedAttachments | Table System.Email."Email Related Attachment" |
Out parameter with the related attachments. |
Returns
| Type | Description |
|---|---|
| Boolean |
True if any related attachments were found; otherwise - false |
Events
OnGetAttachmentContent
Integration event to provide the stream of data for a given MediaID. If attachment content has been deleted, this event makes it possible to provide the data from elsewhere.
[IntegrationEvent(False,False)]
internal procedure OnGetAttachmentContent(MediaID: Guid, var InStream: InStream, var Handled: Boolean)
Parameters
| Name | Type | Description |
|---|---|---|
| MediaID | Guid |
Id of the underlying media field that contains the attachment data. |
| InStream | InStream |
Stream to that should pointed to the attachment data. |
| Handled | Boolean |
Was the attachment content added to the stream. |