Attachments

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 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:

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

Uploading attachments

To upload attachments use the upload attachment method and pass a base64 encoded string for the file content. An array containing an attachment ID will be returned. Use the attachment ID to send the attachment or download it.

const [attachmentId] = await  mailslurp.uploadAttachment({
    base64Contents: new Buffer('hello').toString('base64'),
    contentType: 'text/plain',
    filename: 'test.txt',
})

Downloading attachments

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

const attachment =
    await mailslurp.attachmentController.downloadAttachmentAsBase64Encoded(
        email.attachments?.[0]!
    );
const content = new Buffer(
    attachment.base64FileContents!,
    'base64'
).toString('utf8');
expect(content).toEqual('hello');