Sending attachments in API V3 larger than 3MB via multipart

As a developer it may be easier to send all your emails as multipart/form-data thus allowing for maximum attachment size, note the request_time is longer than sending by JSON.

In order to send large attachments, you should use multipart/form-data format in the headers of the request, see an example using Postman below:

Example of form-data:

Note: the value for message should be similar to:

{
    "subject": "Testing - PDF > 3MB",
    "body": "This is the send message for file > 3MB attachment message,
    "to": [
        {
            "name": "Test Name",
            "email": "test@nylas.com"
        }
    ]
}

 


Using the /send endpoint: 

Here is a CURL example on "sending immediately" with in-line attachment:

curl --request POST \
 --url https://api.us.nylas.com/v3/grants/4de31e94-9886-42e4-8e60-cd701a69d689/messages/send \
 --header 'Authorization: Bearer API-KEY' \
 --header 'content-type: multipart/form-data' \
 --form 'message={
	"body": "Hey there! This is an email testing out inline attachments using the Nylas Email API. Here is what their mascot looks like -- I think she is so cute! /n <img src=\”cid:xyzpqdnyla\"/> /n They also have a cool logo: <img src=\”cid:xyzpdqlogo\"/>.“,
	"subject": "Testing out inline attachments",
	"to": [{
  "email": "reactxxxxxonary@outlook.com",
  "name": "Adrian Traeger"
 }],
}' \
 --form xyzpdqnyla=@/Users/allison/Desktop/nyla.png \
 --form xyzpdqlogo=@/Users/allison/Desktop/logo.png

 


Using the /draft endpoint

Here is a CURL example for draft:

curl --location 'https://api.eu.nylas.com/v3/grants/{{grant_id}}/drafts' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {{NYLAS_API_KEY}}' \
--header 'Content-Type: multipart/form-data' \
--form 'file=@"/path/to/file"' \
--form 'message="{
    \"subject\": \"Testing draft - PDF > 3MB\",
    \"body\": \"This is the draft test for file > 3MB attachment\",
    \"to\": [
        {
            \"name\": \"Test Name\",
            \"email\": \"test@nylas.com\"
        }
    ]
}
"'

 


Sending Inline attachments using form data

Here is an example of sending inline attachments using form data:

curl --location 'https://api.us.nylas.com/v3/grants/{{grant_id}}/messages/send' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {{NYLAS_API_KEY}}' \
--data-raw '{
"attachments": [
{
"content": <base64 encoded attachment> ,
"content_type": "multipart/form-data",
"content_id": "{{content_id}}",
"filename": "{{filename}}",
"size":{{file_size}}
}
],
"bcc": [],
"body":"<div><p>Before image</p><img src='\''cid:c0ec6fcc'\''><p>After image</p></div>",
"cc": [],
"subject": "Testing attachment",
"to": [
{
"email": "test@nylas.com",
"name": "Test Name"
}
]
}
'

 

Resources:

 

Updated

Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.