# Email

**Kind**: interface | **Module**: [Outlook](https://docs.interop.io/adapters/reference/javascript/outlook/index.md)

**Source**: https://docs.interop.io/adapters/reference/javascript/outlook/email/index.html

Represents an email with additional methods for interacting with Outlook.

## Properties

- **`attachments`** (`Attachment[]`, required)
  An array of identifiers for the attachments to the email.
- **`bcc`** (`T42Contact | T42Contact[]`, required)
  The blind co-recipient(s) of the email. If this parameter is missing then there are no blind co-recipients.
- **`body`** (`string`, required)
  The body text of the email, formatted as a plain string.
- **`bodyHtml`** (`string`, required)
  The body of the email, formatted as an HTML string. If the email was not sent in HTML format, then the Helper
  must convert the plain-text body into a valid HTML string by wrapping it in the standard tags.
- **`cc`** (`T42Contact | T42Contact[]`, required)
  The co-recipient(s) of the email. If this parameter is missing then there are no co-recipients.
- **`date`** (`Date`, required)
  The time at which the email was sent, using local time for the sender.
- **`entityType`** (`number`, required)
  The entity type identifier for the email.
- **`ids`** (`T42Id[]`, required)
  Identifiers for the email; globally unique to the system.
- **`sender`** (`T42Contact`, required)
  The originator of the email. This might be only the email address, if the T42Contact has not yet been resolved.
- **`subject`** (`string`, required)
  The subject field of the email.
- **`to`** (`T42Contact | T42Contact[]`, required)
  The primary recipient(s) of the email.

## Methods

### getAsMsg

Returns email, saved as .msg as base64.

```ts
() => Promise<string>
```

**Returns**: `Promise<string>`

**Example**

```ts
```javascript
await outlook.newEmail(
    {
        to: "emailAddress@mail.com",
        subject: "Sample subject",
        body: "Sample body"
    },
    {
        onSent: async (email) => {
            const data = await email.getAsMsg();
            console.log(data);
        }
    }
);
```
```

### saveToFile

Saves email as .msg file.

```ts
() => Promise<string>
```

**Returns**: `Promise<string>`

**Example**

```ts
```javascript
await outlook.newEmail(
    {
        to: "emailAddress@mail.com",
        subject: "Sample subject",
        body: "Sample body"
    },
    {
        onSent: async (email) => {
            const uri = await email.saveToFile();
            console.log(uri);
        }
    }
);
```
```

### show

Shows email in Outlook.

```ts
() => Promise<T42Id[]>
```

**Returns**: `Promise<T42Id[]>`

**Example**

```ts
```javascript
await outlook.newEmail(
    {
        to: "emailAddress@mail.com",
        subject: "Sample subject",
        body: "Sample body"
    },
    {
        onSent: async (email) => {
            const ids = await email.show();
            console.log(ids);
        }
    }
);
```
```

### track

Tracks email.

```ts
(conversationId?: T42Id) => Promise<{ conversationIds: T42Id[], emailIds: T42Id[] }>
```

**Parameters**

- **`conversationId`** (`T42Id`, optional)
  Optional conversation identifier.

**Returns**: `Promise<{ conversationIds: T42Id[], emailIds: T42Id[] }>`

**Example**

```ts
```javascript
outlook.onTrackEmail(async ({ conversationIds, email }) => {
    const result = await email.track();
    console.log(result.conversationIds, result.emailIds);
});
```
```

### untrack

Untracks email.

```ts
() => Promise<{ conversationIds: T42Id[], emailIds: T42Id[] }>
```

**Returns**: `Promise<{ conversationIds: T42Id[], emailIds: T42Id[] }>`

**Example**

```ts
```javascript
outlook.onTrackEmail(async ({ conversationIds, email }) => {
    await email.track();
    const result = await email.untrack();
    console.log(result.conversationIds, result.emailIds);
});
```
```

## Related types

- [Attachment](https://docs.interop.io/adapters/reference/javascript/outlook/attachment/index.md)
- [T42Contact](https://docs.interop.io/adapters/reference/javascript/outlook/t42contact/index.md)
- [T42Id](https://docs.interop.io/adapters/reference/javascript/outlook/t42id/index.md)
