# Attachment

## Overview

Email attachments can be managed through an object providing methods to access their content, properties, and state. Attachments can be created using binary or text files and sent as part of an email.

## Functionality

Email attachments support several operations. The `getData()` method retrieves the content of the attachment as a byte array. `getMimeType()` provides the MIME type, useful for identifying file formats. `getName()` returns the attachment's name for display or logging purposes. The `isEmbedded()` method checks if the attachment is embedded in the email body, determined by references in the email's text content.

These methods enable robust email attachment handling, including retrieving file properties and ensuring proper integration with email body content.

## Methods Summarized

| Type                                                       | Name                          | Summary                                                       |
| ---------------------------------------------------------- | ----------------------------- | ------------------------------------------------------------- |
| [Array](/reference/servoycore/dev-api/js-lib/array.md)     | [getData()](#getdata)         | Returns a byte array with the content of this attachment.     |
| [String](/reference/servoycore/dev-api/js-lib/string.md)   | [getMimeType()](#getmimetype) | Returns the Mime type of this attachment.                     |
| [String](/reference/servoycore/dev-api/js-lib/string.md)   | [getName()](#getname)         | Returns the name of this attachment.                          |
| [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) | [isEmbedded()](#isembedded)   | Returns true if this attachment is embedded, false otherwise. |

## Methods Detailed

### getData()

Returns a byte array with the content of this attachment.

**Returns:** [Array](/reference/servoycore/dev-api/js-lib/array.md) A byte array containing the content of this attachment.

**Sample**

```js
var logo = plugins.mail.createBinaryAttachment('logo.jpg', plugins.file.readFile('d:/logo.jpg'));
var invoice = plugins.mail.createTextAttachment('invoice.txt', plugins.file.readTXTFile('d:/invoice.txt'));
var attachments = new Array(logo, invoice);
var success = plugins.mail.sendMail(toAddress, fromAddress, 'subject line', 'message text', null, null, attachments, properties);
if (!success)
{
	plugins.dialogs.showWarningDialog('Alert', 'Failed to send mail', 'OK');
}
else
{
	plugins.dialogs.showInfoDialog('Success', 'Mail sent', 'OK');
	application.output('logo attachment name: ' + logo.getName());
	application.output('logo attachment mime type: ' + logo.getMimeType());
	application.output('logo attachment size: ' + logo.getData().length);
	application.output('logo attachment embedded state: ' + logo.isEmbedded());
	application.output('invoice attachment name: ' + invoice.getName());
	application.output('invoice attachment mime type: ' + invoice.getMimeType());
	application.output('invoice attachment size: ' + invoice.getData().length);
	application.output('invoice attachment embedded state: ' + invoice.isEmbedded());
}
```

### getMimeType()

Returns the Mime type of this attachment.

**Returns:** [String](/reference/servoycore/dev-api/js-lib/string.md) The MIME type of this attachment.

**Sample**

```js
var logo = plugins.mail.createBinaryAttachment('logo.jpg', plugins.file.readFile('d:/logo.jpg'));
var invoice = plugins.mail.createTextAttachment('invoice.txt', plugins.file.readTXTFile('d:/invoice.txt'));
var attachments = new Array(logo, invoice);
var success = plugins.mail.sendMail(toAddress, fromAddress, 'subject line', 'message text', null, null, attachments, properties);
if (!success)
{
	plugins.dialogs.showWarningDialog('Alert', 'Failed to send mail', 'OK');
}
else
{
	plugins.dialogs.showInfoDialog('Success', 'Mail sent', 'OK');
	application.output('logo attachment name: ' + logo.getName());
	application.output('logo attachment mime type: ' + logo.getMimeType());
	application.output('logo attachment size: ' + logo.getData().length);
	application.output('logo attachment embedded state: ' + logo.isEmbedded());
	application.output('invoice attachment name: ' + invoice.getName());
	application.output('invoice attachment mime type: ' + invoice.getMimeType());
	application.output('invoice attachment size: ' + invoice.getData().length);
	application.output('invoice attachment embedded state: ' + invoice.isEmbedded());
}
```

### getName()

Returns the name of this attachment.

**Returns:** [String](/reference/servoycore/dev-api/js-lib/string.md) The name of this attachment.

**Sample**

```js
var logo = plugins.mail.createBinaryAttachment('logo.jpg', plugins.file.readFile('d:/logo.jpg'));
var invoice = plugins.mail.createTextAttachment('invoice.txt', plugins.file.readTXTFile('d:/invoice.txt'));
var attachments = new Array(logo, invoice);
var success = plugins.mail.sendMail(toAddress, fromAddress, 'subject line', 'message text', null, null, attachments, properties);
if (!success)
{
	plugins.dialogs.showWarningDialog('Alert', 'Failed to send mail', 'OK');
}
else
{
	plugins.dialogs.showInfoDialog('Success', 'Mail sent', 'OK');
	application.output('logo attachment name: ' + logo.getName());
	application.output('logo attachment mime type: ' + logo.getMimeType());
	application.output('logo attachment size: ' + logo.getData().length);
	application.output('logo attachment embedded state: ' + logo.isEmbedded());
	application.output('invoice attachment name: ' + invoice.getName());
	application.output('invoice attachment mime type: ' + invoice.getMimeType());
	application.output('invoice attachment size: ' + invoice.getData().length);
	application.output('invoice attachment embedded state: ' + invoice.isEmbedded());
}
```

### isEmbedded()

Returns true if this attachment is embedded, false otherwise. Attachments become embedded if they are references through tags from the body text of the message.

**Returns:** [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) true if this attachment is embedded; false otherwise.

**Sample**

```js
var logo = plugins.mail.createBinaryAttachment('logo.jpg', plugins.file.readFile('d:/logo.jpg'));
var invoice = plugins.mail.createTextAttachment('invoice.txt', plugins.file.readTXTFile('d:/invoice.txt'));
var attachments = new Array(logo, invoice);
var success = plugins.mail.sendMail(toAddress, fromAddress, 'subject line', 'message text', null, null, attachments, properties);
if (!success)
{
	plugins.dialogs.showWarningDialog('Alert', 'Failed to send mail', 'OK');
}
else
{
	plugins.dialogs.showInfoDialog('Success', 'Mail sent', 'OK');
	application.output('logo attachment name: ' + logo.getName());
	application.output('logo attachment mime type: ' + logo.getMimeType());
	application.output('logo attachment size: ' + logo.getData().length);
	application.output('logo attachment embedded state: ' + logo.isEmbedded());
	application.output('invoice attachment name: ' + invoice.getName());
	application.output('invoice attachment mime type: ' + invoice.getMimeType());
	application.output('invoice attachment size: ' + invoice.getData().length);
	application.output('invoice attachment embedded state: ' + invoice.isEmbedded());
}
```

***


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.servoy.com/reference/servoyextensions/server-plugins/mail/attachment.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
