What is the best way to send an inline attachment?

Hey guys, how u doing? I hope you are well.

I’m using the Node SDK (version 7.2.1), and I’m experiencing a problem:
What is the best way to send an inline attachment? Base64? Because in the docs I saw that it is sending the attachment ID, but how can I get an attachment ID if the attachments don’t have a POST endpoint?

Hi @VictorMonteiro7 - doing well, thanks for the message! How are you?

Nylas SDKs should support both formats: binary and base64, let me double check this with the team and circle back shortly :+1:

Hey @ram, thanks for the quickly reply. I’m doing well, thanks for asking.
Okay, I’ll wait.

1 Like

@VictorMonteiro7 taking a look at this and it seems we do not support base64 in the current SDK and are taking a look at this very soon.

Let me circle back when the Node SDK is updated to support this :+1:

Oh, that’s sad, but okay.
@ram I found another problem (I guess):
I’m trying to send a draft with attachments, but I can’t. When I send a message, it’s all ok (I do it with a single file less then 3MB, greater then 3MB, e multiple files). But, trying to send with a draft, when a file is less then 3MB, it send the email without the attachment, and, when the file has more then 3MB, it throws me an error NOT_IMPLEMENTED. Can you see this to me?

Hi @VictorMonteiro7 can you share a code snippet or code sample of how you are trying to send the attachments?

I see that files larger than 3MB require a different approaching to sending files, so have to double check if this is supported by the SDK (hence the message NOT_IMPLEMENTED may be relevant).

@ram
That’s the object when I do a GET to drafts endpoint:

{
    "starred": false,
    "unread": false,
    "folders": [
        "<Folder-ID>"
    ],
    "subject": "Test",
    "threadId": "<Thread-ID>",
    "grantId": "<Grant-ID>",
    "body": "<html><head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"></head><body><a href=\"https://tracking.us.nylas.com/l/26f79d34b3cd47b19a7fe9c5f993e7ee/0/650703a23b560c8362b021b8705763d028302ea9d463eaae41c21169e96326dc?cache_buster=1713984436\">Um link para o Google!</a> Bem vindo!<img width=\"1\" height=\"1\" alt=\"tracking\" src=\"https://tracking.us.nylas.com/o/fbaaa90f23bf445592abbae71ffebb07/335ed8d7f95db559e7d2209bd832b91d8002af14aceaf4c49fd324507939a21a?cache_buster=1713984436\" style=\"border:0; width:1; height:1; display:none\"> </body></html>",
    "id": "<Draft-ID>",
    "object": "draft",
    "snippet": "Um link para o Google! Bem vindo!",
    "from": [
        {
            "email": "victormonteiro7@outlook.com"
        }
    ],
    "to": [
        {
            "name": "Victor",
            "email": "contato@ovictormonteiro.com"
        }
    ],
    "date": 1713984437,
    "createdAt": 1713984436,
    "updatedAt": 1713984437
}

I used the draft-id above to update the draft with the attachments

Image Greater Than 3MB

I will send more images on next comments

1 Like

Image Less Than 3MB

Multiple sizes

Remembering:
All errors is only when I do it with Nylas.drafts.update function (or, when have only <3MB files, Nylas.drafts.send don’t send the attachment). When I send with Nylas.messages.send function, it works fine.

@VictorMonteiro7 thanks for sharing - let me circle back after the SDK is updated and try out the different image sizes :+1:

Just to clarify, the error occurs when:

  1. calling Nylas.drafts.update for file sizes larger than 3 MB
  2. calling Nylas.drafts.send for file sizes smaller than 3 MB

Yes. I would add one more:
3. Calling Nylas.drafts.update for multiple files with diferents sizes (larger than 3MB e less than 3MB).

@VictorMonteiro7 - still waiting on a resolution on this, I see you are reviewing the open PR, thanks!

Hey @ram, thanks for the response. I’ll be waiting for the resolution.

Hi @VictorMonteiro7 the PR is merged, let me know if there is anything else we can do to help!

Hey @ram, I saw this when they merged and version 7.4.0 arrived, but my biggest problem is: in Nylas v3 I’m sending inline attachments as base64, but gmail doesn’t accept base64 in the email body. In Nylas v2 there was a file post endpoint, so I sent the file and received the ID, and with that I changed the img src to cid:<file-id>, which is impossible to do in v3. How can I do this?

Hi @VictorMonteiro7 just checking some notes on this and Nylas API v3 does not have a file upload endpoint, only attaching files as part of email draft / send endpoints.

I see that gmail doesn’t accept base64, this may be something you need to implement for. I would try recommend you to consider what other formats or approaches you can consider for adding images to an email body.

Yep. I’ll appreciate that.

Hey @ram, I solved the problem.
The Nylas doesn’t have the POST /attachments endpoint anymore, but, I understood that I have to send the attachment with a generated ID and change the src on image.
So, instead use an endpoint to send an image, I just generated in our side an uuid and send the attachment with is_inline parameter.

1 Like

@ram @VictorMonteiro7
I tried using the /send endpoint with in_line parameters for attachments, but the email content is still not displaying as inline when sent to Outlook. Can you help me figure out what might be going wrong?

Hey @ritulg, which version are you using? Are you using some SDK? Can you send here how do you is sending the message?