Attachments are a way to send and receive files with in emails.

## Sending attachments

Send attachments using the compose page in the dashboard or by using the `sendEmail` [methods](https://mailslurp.github.io/mailslurp-client/interfaces/SendEmailOptions.html) with a list of attachment IDs. Attachment IDs can be created by uploading files before sending (see next section). Here is an example using the NodeJS client:



```typescript
await mailslurp.sendEmail(inbox.id!, {
  to: [inbox.emailAddress!],
  subject: "attachment test",
  attachments: [attachmentId.toString()],
});
```



## Uploading attachments

![smtp attachments](/assets/photos/paperclip.jpg)

To upload attachments use the upload attachment method and pass a [base64 encoded string](/guides/base64-file-uploads/) for the file content. An array containing an attachment ID will be returned. Use the attachment ID to send the attachment or download it.



```typescript
// notice that an array with one attachment id is returned
const [attachmentId] = await mailslurp.uploadAttachment({
  base64Contents: Buffer.from("hello").toString("base64"),
  contentType: "text/plain",
  filename: "test.txt",
});
```



## Downloading attachments

Here is how to download files found on an email object.



```typescript
const attachment = await mailslurp.attachmentController.downloadAttachmentAsBase64Encoded({
  attachmentId: email.attachments?.[0]!,
});
const content = new Buffer(attachment.base64FileContents!, "base64").toString("utf8");
expect(content).toEqual("hello");
```


