# Read PDFs & sending as Gmail attachments

**URL:** <https://connective.celigo.com/t/read-pdfs-sending-as-gmail-attachments/2875>\
**Category:** Integrator.io\
**Tags:** google-mail, connectivity\
**Created:** [January 28, 2025, 9:59am UTC](https://connective.celigo.com/t/read-pdfs-sending-as-gmail-attachments/2875 "2025-01-28T09:59:12Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![tharakaathukorala](https://avatars.discourse-cdn.com/v4/letter/t/ecb155/32.png) [@tharakaathukorala](https://connective.celigo.com/u/tharakaathukorala)\
**Post date:** [January 28, 2025, 9:59am UTC](https://connective.celigo.com/t/read-pdfs-sending-as-gmail-attachments/2875/1 "2025-01-28T09:59:12Z")

</div>

Hi there,

Is it possible to read PDF files from an SFTP and send them as Gmail attachments through Celigo?

If so can you kindly share a documentation with me?

Thanks

---

<div class="post-metadata">

**Author:** ![kathyanaqueeman](https://sea1.discourse-cdn.com/flex001/user_avatar/connective.celigo.com/kathyanaqueeman/32/9122_2.png) [@kathyanaqueeman](https://connective.celigo.com/u/kathyanaqueeman)\
**Post date:** [January 28, 2025, 9:08pm UTC](https://connective.celigo.com/t/read-pdfs-sending-as-gmail-attachments/2875/2 "2025-01-28T21:08:46Z")

</div>

Hi @tharakaathukorala,

I think you asked [a similar question a few years ago](https://connective.celigo.com/t/send-csv-attachments-using-gmail-connector/491). The Google Mail connector doesn't support sending attachments, but you could do it through a universal HTTP connection. According to Google Mail's REST API, you can upload an attachment as multipart/form-data. Here are some steps you'll need to follow:

1. [Create an HTTP connection](https://docs.celigo.com/hc/en-us/articles/360039586072-Set-up-an-OAuth-2-0-HTTP-connection)
2. [Google Mail upload attachments REST API instructions](https://developers.google.com/gmail/api/guides/uploads)
3. [Import files into an HTTP destination app](https://docs.celigo.com/hc/en-us/articles/23181175479707-Import-files-into-an-HTTP-destination-app#import-files-into-an-http-destination-app-0)
4. [Upload a file or record as multipart/form-data](https://docs.celigo.com/hc/en-us/articles/360052055191-Upload-a-file-or-record-as-multipart-form-data#c-build-the-request-body-3)

If you have any further questions, feel free to comment here or make a separate post in the community! Thanks!

---

<div class="post-metadata">

**Author:** ![kathyanaqueeman](https://sea1.discourse-cdn.com/flex001/user_avatar/connective.celigo.com/kathyanaqueeman/32/9122_2.png) [@kathyanaqueeman](https://connective.celigo.com/u/kathyanaqueeman)\
**Post date:** [January 28, 2025, 9:10pm UTC](https://connective.celigo.com/t/read-pdfs-sending-as-gmail-attachments/2875/3 "2025-01-28T21:10:57Z")

</div>

A note: I've moved your post to the [Troubleshoot custom flows](https://connective.celigo.com/c/6) section of the Community for more visibility.

---

<div class="post-metadata">

**Author:** ![tharakaathukorala](https://avatars.discourse-cdn.com/v4/letter/t/ecb155/32.png) [@tharakaathukorala](https://connective.celigo.com/u/tharakaathukorala)\
**Post date:** [January 29, 2025, 3:12am UTC](https://connective.celigo.com/t/read-pdfs-sending-as-gmail-attachments/2875/4 "2025-01-29T03:12:33Z")

</div>

Thanks Kathyana.

---

<div class="post-metadata">

**Author:** ![tylerlamparter](https://sea1.discourse-cdn.com/flex001/user_avatar/connective.celigo.com/tylerlamparter/32/9204_2.png) [@tylerlamparter](https://connective.celigo.com/u/tylerlamparter)\
**Post date:** [January 29, 2025, 3:27am UTC](https://connective.celigo.com/t/read-pdfs-sending-as-gmail-attachments/2875/5 "2025-01-29T03:27:11Z")

</div>

@tharakaathukorala it's possible, but not easy. There is a template in the marketplace that I created for sending google mail emails with attachments, but it requires you to have the file represented as a base64 encoded string. So the main issue is converting the pdfs you get from your FTP server and converting it the base64 encoded string. We don't currently have a way to convert the blobKey you get into this. You would need to make an intermediate step to convert the blob to base64 encoded string like this: [https://connective.celigo.com/t/faq-convert-a-blob-key-to-base64-string-for-import/358](https://connective.celigo.com/t/faq-convert-a-blob-key-to-base64-string-for-import/358) Alternatively, if you have NetSuite, I could create a better method using NetSuite as an intermediary and post it here.

---

<div class="post-metadata">

**Author:** ![tharakaathukorala](https://avatars.discourse-cdn.com/v4/letter/t/ecb155/32.png) [@tharakaathukorala](https://connective.celigo.com/u/tharakaathukorala)\
**Post date:** [January 29, 2025, 4:07am UTC](https://connective.celigo.com/t/read-pdfs-sending-as-gmail-attachments/2875/6 "2025-01-29T04:07:41Z")

</div>

Hi Tyler,

Appreciate your guidance.

We also already created an integration to send base64 encoded JSON data as attachments via a Gmail HTTP connector.

```
import sjcl from 'sjcl';
base64Encode: (str) => {
        return sjcl.codec.base64.fromBits(sjcl.codec.utf8String.toBits(str));
    }
```

Now we are stuck on sending PDFs through Gmail. According to my understanding, the Celigo does not support converting PDFs to base64 string.

I will further dig into your solution.

Thanks again.

---

<div class="post-metadata">

**Author:** ![Sriram\_Ramji](https://avatars.discourse-cdn.com/v4/letter/s/e8c25b/32.png) [@Sriram\_Ramji](https://connective.celigo.com/u/Sriram_Ramji)\
**Post date:** [January 5, 2026, 11:28am UTC](https://connective.celigo.com/t/read-pdfs-sending-as-gmail-attachments/2875/7 "2026-01-05T11:28:57Z")

</div>

Hi Tharaka, I noticed that you previously faced a similar issue when sending a PDF via email. I’m currently experiencing a related issue while sending an EDI file as an email attachment. Have you found any solution that might help?

---

<div class="post-metadata">

**Author:** ![tylerlamparter](https://sea1.discourse-cdn.com/flex001/user_avatar/connective.celigo.com/tylerlamparter/32/9204_2.png) [@tylerlamparter](https://connective.celigo.com/u/tylerlamparter)\
**Post date:** [January 6, 2026, 1:35am UTC](https://connective.celigo.com/t/read-pdfs-sending-as-gmail-attachments/2875/8 "2026-01-06T01:35:58Z")

</div>

What does your current flow look like? Are you parsing the edi file or just getting the file blob key for it?

---

<div class="post-metadata">

**Author:** ![tharakaathukorala](https://avatars.discourse-cdn.com/v4/letter/t/ecb155/32.png) [@tharakaathukorala](https://connective.celigo.com/u/tharakaathukorala)\
**Post date:** [January 6, 2026, 5:41am UTC](https://connective.celigo.com/t/read-pdfs-sending-as-gmail-attachments/2875/9 "2026-01-06T05:41:41Z")

</div>

Hi experts,

The following steps were taken to overcome this issue.

**Problem definition**

Read the files and email them as attachments using Gmail.

**Approach used to overcome the problem**

- Read files from Celigo. (i.e SFTP)

- Do not parse the files. The files should simply be transferred raw as-is (i.e. PDFs, JPGs, etc.)

- Convert the binary file using AWS (Lambda function) into a base64 string. Write a simple lambda function to convert any binary file into a base64 string with your preferred language.

1. Create a [connection for AWS](https://docs.celigo.com/hc/en-us/articles/40593290735259-Set-up-a-connection-to-AWS-Service#set-up-a-connection-to-aws-service-0) within Celigo. And follow the configurations below.
  1. HTTP request =\> POST
  2. Sample URI =\> https://\*\*\*\*\*\*\*.lambda-url.eu-north-1.on.aws/api/v1/bin2base64
  3. Override request media type =\> Multipart / form-data
  4. HTTP request body =\> [  
{  
"name": "file",  
"filename": "{{record.fileMeta.fileName}}",  
"type": "attachment",  
"mime-headers": {},  
"value": "{{blob}}"  
}]
  5. Add the Blob key path =\> blobKey

- Get the base64 string for your binary file and merge it into the response mapping.

- Send the base64 string as attachments in Gmail.

1. Create a [universal HTTP connection](https://docs.celigo.com/hc/en-us/articles/360039586072-Set-up-an-OAuth-2-0-HTTP-connection#set-up-an-oauth-2-0-http-connection-0) in Celigo for Gmail.
  1. Base URI =\> [https://www.googleapis.com](https://www.googleapis.com)
  2. Auth type =\> Auth2.0
    1. Grant type =\> Authorization code
    2. Client ID =\> Add the client ID from the Google console.
      1. Ref - [Learn about authentication and authorization &nbsp;|&nbsp; Google Workspace &nbsp;|&nbsp; Google for Developers](https://developers.google.com/workspace/guides/auth-overview) , [Gmail API Overview &nbsp;|&nbsp; Google for Developers](https://developers.google.com/workspace/gmail/api/guides) , [https://docs.celigo.com/hc/en-us/articles/21552253434523-Available-Google-Mail-APIs#UUID-129dc558-fd2d-1f17-7b44-d0defd1fee55](https://docs.celigo.com/hc/en-us/articles/21552253434523-Available-Google-Mail-APIs#UUID-129dc558-fd2d-1f17-7b44-d0defd1fee55)

    3. Add the Client secret
    4. Send client credentials via =\> HTTP Body
    5. Authorization URL =\> [https://accounts.google.com/o/oauth2/auth](https://accounts.google.com/o/oauth2/auth)
    6. Access token URL =\> [https://oauth2.googleapis.com/token](https://oauth2.googleapis.com/token)
    7. Valid domain names =\> [googleapis.com](http://googleapis.com),[accounts.google.com](http://accounts.google.com),[oauth2.googleapis.com](http://oauth2.googleapis.com),[google.com](http://google.com)
    8. Send token =\> Authorization HTTP Bearer

  3. Scope =\> [https://www.googleapis.com/auth/gmail.send](https://www.googleapis.com/auth/gmail.send)
  4. Save & Authorize.

2. Use the HTTP Gmail connection to send the attachments.
  1. HTTP method =\> POST
  2. Request URL =\> [https://www.googleapis.com/gmail/v1/users/me/messages/send](https://www.googleapis.com/gmail/v1/users/me/messages/send)
  3. HTTP headers =\> Content-Type: message/rfc822
  4. HTTP request body =\> {  
"raw": "{{data.[0].base64ConvertedEmailStr}}"  
}

Refer to the below **sample** block of code to get the base64ConvertedEmailStr.

```javascript
import sjcl from 'sjcl';

functionName_PreMap: (options) => {
    let PDFData = options.data;
    const toEmails = options.settings.email_recipents;
    const fromEmail = 'from email address';
    const emailSubject = "Mail Subject";
    let emailTemplate = `<div style="background-color: #f9f9f9; padding: 20px 40px; margin: 0 100px">
<p> <span style="font-weight: 400;">Hello,</span> </p>
<p> <span style="font-weight: 400;">Your Message</span> </p>`;

    PDFData.forEach((file) => {
        let fileName = file.fileMeta.fileName;
    });

    emailTemplate += `<p> <span style="font-weight: 400;">This is an automated notification.</span> </p>
<p>Thank you.</p></div>`;

    let fileContentString = PDFData.map((content, index) => {
        return `Content-Type: application/pdf; charset="UTF-8"

Content-Transfer-Encoding: base64
MIME-Version: 1.0
Content-Disposition: attachment; filename="${content.fileMeta.fileName}"
Content-ID: <content_${index + 1}>

${content.data.base64}\n`; // Assuming content is base64 encoded accordingly
}).join('--celigo_email_boundary\n');

    let emailStr = `Content-Type: multipart/mixed; boundary=celigo_email_boundary

MIME-Version: 1.0
to: ${toEmails}
from: ${fromEmail}
subject: ${emailSubject}

--celigo_email_boundary
Content-Type: text/html; charset="UTF-8"
MIME-Version: 1.0

${emailTemplate}

--celigo_email_boundary
${fileContentString}
--celigo_email_boundary--`;

    emailStr = Util.base64Encode(emailStr);
    if (emailStr.endsWith('=')) {
        emailStr = emailStr.replace(/=+$/, '');
    }

    options.data[0].base64ConvertedEmailStr = emailStr;

    return options.data.map((d) => {

        if (d.base64ConvertedEmailStr) {
            return {
                data: d
            }
        } else {
            return {
                data: null
            }
        }
    });
}

const Util = {
    base64Encode: (str) => {
        return sjcl.codec.base64.fromBits(sjcl.codec.utf8String.toBits(str));
    }
}

```

---

<div class="post-metadata">

**Author:** ![tylerlamparter](https://sea1.discourse-cdn.com/flex001/user_avatar/connective.celigo.com/tylerlamparter/32/9204_2.png) [@tylerlamparter](https://connective.celigo.com/u/tylerlamparter)\
**Post date:** [January 6, 2026, 3:47pm UTC](https://connective.celigo.com/t/read-pdfs-sending-as-gmail-attachments/2875/10 "2026-01-06T15:47:19Z")

</div>

You no longer need a Lambda function and can use this:

> [@FAQ: Convert a blob key to base64 string for import?](https://connective.celigo.com/t/faq-convert-a-blob-key-to-base64-string-for-import/358/4):
>
> I built a different way to do this which is all in Celigo. If you go to the marketplace, you can find it under "Blobkey Conversion Helper". With this being said, you normally do not need to use this. Normally, if you need to send base64 to your endpoint, you'd do something like this if you already have a blobKey: If …

---

<div class="post-metadata">

**Author:** ![tharakaathukorala](https://avatars.discourse-cdn.com/v4/letter/t/ecb155/32.png) [@tharakaathukorala](https://connective.celigo.com/u/tharakaathukorala)\
**Post date:** [January 7, 2026, 4:33am UTC](https://connective.celigo.com/t/read-pdfs-sending-as-gmail-attachments/2875/11 "2026-01-07T04:33:01Z")

</div>

Thank you very much, Tyler. That’s awesome.  
We built the AWS solution a couple of years ago.
