Adding Attachments

Attachments are commonly added to emails and when sending with the API, there are two ways they can be included using the "attachments" parameter.

A fileblob of base64 encoded data

Here’s an example using cURL:

"attachments": [
    {
      "filename": "testfile.pdf",
      "fileblob": "--base64-data--",
      "mimetype": "application/pdf"
   }
]

You can encode files using free online services such as Base64 Encode.

A URL address where SMTP2GO will fetch the data

You can set a URL pointing to a web address where SMTP2GO will fetch the data rather than having to inline it with the POST request.

Here’s an example using cURL:

"attachments": [
  {
   "filename": "test.jpg",
   "url": "https://mydomain.com/myimage.jpg,
   "mimetype": "image/jpeg"
  }
]

A full request example - fileblob

A full request example using cURL to send a basic email with a PDF attachment as a fileblob.

curl --request POST \
     --url https://api.smtp2go.com/v3/email/send \
     --header 'Content-Type: application/json' \
     --header 'X-Smtp2go-Api-Key: api-xxxxxxxxxxxxxxxxxx' \
     --header 'accept: application/json' \
     --data '
{
  "sender": "[email protected]",
  "to": [
    "[email protected]"
  ],
  "subject": "SMTP2GO attachment",
  "text_body": "Hello - find the email attached",
	"attachments": [
    {
      "filename": "testfile.pdf",
      "fileblob": "--base64-data--",
      "mimetype": "application/pdf"
   	}
	]
  
}
'

Attachment Size

The maximum email size when sending via the API is 10 MB (this includes content, attachments and headers).