How to retrieve EML files via Spotler SendPro?

In Spotler SendPro, you can retrieve the complete archived version of a sent email as an EML file through the Spotler SendPro (Flowmailer) API. You request the message archive with the message ID, Base64-decode the data value from the response, and save the decoded result as an .eml file. This works only for messages that have passed through an Archive FlowStep.

An EML file is a standard file format that stores one complete email message in MIME format. You can use EML files retrieved from Spotler SendPro for external archiving or storage. The archived EML file contains the full sent message:

  • message headers such as From, To, and Subject
  • the formatted and/or plain-text message content
  • the complete MIME structure
  • all attachments
  • the related Content-Type headers

Because attachments are already part of the archived message, you do not need to retrieve or rebuild attachments separately.

On this page, the following topics are covered:

Before you start

An archive is only available through the Spotler SendPro API if the message has been processed by an Archive FlowStep. 

Archive Flowstep.webp

If the applicable Flow does not contain an Archive FlowStep, or if the message does not pass through that FlowStep, the archive endpoint does not return archive data for the message.

The availability and retention period of archived messages can also depend on the configuration of your Spotler SendPro account.

The full process consists of these steps:

  1. Obtain the message ID.
  2. Retrieve the archived message.
  3. Base64-decode the data value.
  4. Save the decoded data as an .eml file.

Step 1: Obtain the message ID

The message ID uniquely identifies a message in Spotler SendPro, and the archive endpoint requires it. How you obtain the message ID depends on how the message was submitted to Spotler SendPro.

Messages submitted through the Spotler SendPro API

When you submit a message through the Spotler SendPro API, for example with the endpoint below, Spotler SendPro returns the location of the created message in the HTTP Location response header.

POST https://api.flowmailer.net/{account_id}/messages/submit

Example of a Location response header:

Location: https://api.flowmailer.net/{account_id}/messages/202609021323277a4ac9e100001dc349

The last part of this URL is the message ID, in this example 202609021323277a4ac9e100001dc349. Store the message ID as part of your sending process, directly after submission. This is the most efficient way to retrieve the archive at a later moment.

Messages submitted through SMTP or another source

When a message is submitted to Spotler SendPro through SMTP, for example from Spotler Mail+, the sending system does not always receive a Location response header. In that case, use the messages endpoint of the Spotler SendPro API to find recently processed messages and their message IDs:

GET https://api.flowmailer.net/{account_id}/messages

You can query this endpoint periodically. The polling strategy and the way you match a Spotler SendPro message to the corresponding message in the originating system depend on your own implementation.

Step 2: Retrieve the message archive

When you know the message ID, request the archived message from the Spotler SendPro API with the archive endpoint:

GET https://api.flowmailer.net/{account_id}/messages/{message_id}/archive

Do not send the version-specific Accept header

Other Spotler SendPro API endpoints may use a version-specific JSON Accept header, such as Accept: application/vnd.flowmailer.v1.17+json;charset=UTF-8. Do not send this header with the archive request, so the server can return the archive response without requesting that specific media type.

The archive response contains a data property. The data property holds the complete MIME representation of the archived email, encoded as Base64. Simplified example of an archive response:

[
  {
    "data": "base64 result",
    "flowStepId": "123456",
    "messageType": "EMAIL",
    "onlineVersion": true
  }
]

Depending on the API response and your account configuration, the archive response can contain additional metadata.

Step 3: Decode the data and save it as an EML file

The data value from the archive response must be Base64-decoded before you can save it as an EML file. In your implementation:

  1. Read the data value from the JSON archive response.
  2. Base64-decode the value.
  3. Keep the decoded result as binary data.
  4. Write the result to a file with the .eml extension, for example message.eml.

Write the decoded data as bytes

Write the decoded value to the file as bytes, not as regular application text. Processing the content as text can damage the MIME structure and the attachment data in the EML file.

What is the result?

The result is an .eml file that contains the complete archived message from Spotler SendPro, with the original MIME structure, headers, message content, and attachments. You can store this file directly in an external archiving or storage application. A decoded EML file begins with the message headers, for example:

MIME-Version: 1.0
From: sender@example.com
To: recipient@example.com
Subject: Example message
Content-Type: multipart/mixed; ...

After the headers, the MIME structure contains the message body and, where applicable, the attachments and other MIME parts.