question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[firestore-send-email] Unable to send base64 encoded attachment

See original GitHub issue

[READ] Step 1: Are you in the right place?

Issues filed here should be about bugs for a specific extension in this repository. If you have a general question, need help debugging, or fall into some other category use one of these other channels:

  • For general technical questions, post a question on StackOverflow with the firebase tag.
  • For general Firebase discussion, use the firebase-talk google group.
  • To file a bug against the Firebase Extensions platform, or for an issue affecting multiple extensions, please reach out to Firebase support directly.

[REQUIRED] Step 2: Describe your configuration

// ? send the email notification
      return await db.collection('mail').add({
        to:email,
        template: {
          name: 'template',
          data: {
            ...
          },
          attachments: [
            {
              filename: `Invoice-${invoice.invoice_number}.pdf`,
              content: pdf.toString('base64'),
              encoding: 'base64',
              contentType: 'application/pdf'
            }
          ]
        }
      })
  • Extension name: firestore-send-email
  • Extension version: 0.1.17
  • Configuration values (redact info where appropriate):
DEFAULT_FROM=support@_.com
DEFAULT_REPLY_TO=support@_.com
LOCATION=us-central1
MAIL_COLLECTION=mail
SMTP_CONNECTION_URI=smtps://email_address@smtp.gmail.com:465
SMTP_PASSWORD=password
TEMPLATES_COLLECTION=mail_templates
USERS_COLLECTION=users

[REQUIRED] Step 3: Describe the problem

The extension does not process a base64 encoded attachment. The email is successfully send, however, the email does not have a file attachment.

Steps to reproduce:

Create a record in the mail collection

image

Expected result

The email should have a PDF attachment.

Actual result

There is no attachment in the received email.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
dackers86commented, May 27, 2022

@atanaskanchev I think I understand, does this example meet your requirements?

  await firestore().collection("templates").doc("base64_example").set({
    html: "{{html_data}}",
    subject: "{{subject_data}}",
  });

  await firestore()
    .collection("mail")
    .add({
      to: ["darren@invertase.io"],
      message: {
        attachments: [
          {
            filename: `ImportantDocument.pdf`,
            content: "",
            encoding: "base64",
          },
        ],
      },
      template: {
        name: "base64_example",
        data: { html_data: "This is html", subject_data: "This is a subject" },
      },
    });
0reactions
atanaskanchevcommented, May 27, 2022

@dackers86 this works perfectly, thanks for your help!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Firebase email trigger extension: can't attach pdf file
I'm trying to send the pdf as text (or encoded text) and not upload the file to some storage and then just send...
Read more >
Upload files with Cloud Storage on Web - Firebase
If a Blob , File , or Uint8Array isn't available, you can use the uploadString() method to upload a raw, base64 , base64url...
Read more >
Upload base64 string to Firebase Storage - Google Groups
I am trying to create a Google function that will accept base64 string and save to the Firebase Storage. I've tried two versions,...
Read more >
Base64 Encoding | Cloud Vision API - Google Cloud
You can provide image data to the Vision API by specifying the URI path to the image, or by sending the image data...
Read more >
Why is base64 needed (aka why can't I just email a binary file)?
MIME message parts can have "Content-Transfer-Encoding: 8bit", indicating that they are not encoded in any way. However, the SMTP protocol ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found