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 of 25MB, 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":

curl --location 'https://api.us.nylas.com/v3/grants/{{grant_id}}/messages/send' \
--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 message - PDF > 3MB",
"body": "This is the message test for file > 3MB attachment",
"to": [{
"name": "Test Name",
"email": "test@nylas.com"
}]
}'

 


Using the /draft endpoint

Here is a CURL example for draft:

curl --location 'https://api.us.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 --request POST \
--url https://api.us.nylas.com/v3/grants/{{grant_id}}/messages/send \
--header 'Authorization: Bearer {{NYLAS_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! <br> <img src=\"cid:xyzpdqnyla\"/> <br> They also have a cool logo: <img src=\"cid:xyzpdqlogo\"/>.",
"subject": "Testing out inline attachments",
"to": [{
"email": "test@outlook.com",
"name": "Adrian Traeger"
}]
}' \
--form xyzpdqnyla=@/Users/TestPath/Desktop/nyla.png \
--form xyzpdqlogo=@/Users/TestPath/Desktop/logo.png

 


Sending one email that has an inline attachment and a regular attachment.

For example:

Here is an example of sending one inline attachment and one attached attachment using form data:

curl --location 'https://api.us.nylas.com/v3/grants/{{grant_id}}/messages/send' \
--header 'Authorization: Bearer {{NYLAS_API_KEY}}' \
--form 'message={
"body": "Before image <br> <img src=\"cid:xyzpdqnyla\"/> <br> After image",
"subject": "Testing out inline attachments",
"to": [{
"email": "test@test.com",
"name": "Test Name"
}]
}' \
--form 'xyzpdqnyla=@/Users/TestPath/Desktop/nyla.png' \
--form 'xyzpdqlogo=@/Users/TestPath/Desktop/logo.png'

 

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.