How to fetch email message and attachments in code

How to read emails and attachments in applications, tests, or the MailSlurp dashboard. Fetch SMTP messages body parts, headers, and files.

  • Table of contents

See the full email receive guide for more information.

Capturing emails

You can use MailSlurp to capture real emails and attachments in applications, tests, or using the MailSlurp Dashboard.

Inbox routing

In order to receive emails with MailSlurp you must first create an inbox. Each inbox has an id and an emailAddress. Any email sent to the inbox's email address will be captured by MailSlurp and stored in the inbox.

Note: emails can take up to a minute to arrive. This is due to the asynchronous nature of SMTP and email. If you developing with MailSlurp considering using Webhooks or waitFor methods.

Listing received emails

You can see a list of all the emails an inbox has received on the overview page for a given inbox. You can also use the getEmails(inboxId) methods in the SDKs libraries.

Viewing email content

You can view the content of an email by clicking view in the inbox overview page or by using the getEmail(emailId) methods in the API.

Overview

The Dashboard email overview page contains a number of sections. The first is an overview of the email including the to, from, and subject headers:

email overview

Content

The body of an email is available in several formats: plain-text, HTML preview, and RAW.

Plain Text

email text content

HTML Preview

MailSlurp renders a real HTML preview of your email. Note some email clients may render results differently. Images are available for paid plans.

email text content

RAW

Raw SMTP email content is available under the RAW tab in the content pane. This is useful for deep email analysis.

Attachments

You can capture and download real attachments with MailSlurp in code, tests, or using the Dashboard. If an email was received that contained attachments they will be listed in the attachments section. The can also be obtains via the getEmail(emailId) and downloadAttachment(attachmentId) developer endpoints.

receive attachents

Spam anaysis

MailSlurp performs powerful SPAM analysis on every email. You can view the results in the email analysis section:

email analysis