Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

375
Visualizações
Embedded images in email with sendgrid

Trying to use an embedded image in my template but the email won't be sent. The path should be correct and I am getting no error. When I delete the image everything works fine and I am receiving the mail.

const mailController = {
sendAnswers: async(certificate) => {
    try {
        let pathToAttachment = `./documents/${certificate.company.name}/${certificate.company.name}_${certificate.company.selectedLanguage}.pdf`;
        let attachment = fs.readFileSync(pathToAttachment).toString("base64");

        let answerTemplate = {
            to: 'invoice@test.de',
            from: 'no-reply@test.de', // Use the email address or domain you verified above
            subject: 'Test',
            text: 'Test Test Test',
            html: `
                <img alt="test" src="cid:logo">
                <div style="margin: 20px 20%; padding: 24px; border: 1px solid rgba(0, 0, 0, 0.2); border-radius: 6px;"><h1 style="text-align: center">Thank You! ${certificate.company.name}</h1>
                <p style="text-align: center">Text<br>
                More Text
                More and More Text</p>
                </div>
            `,
            attachments: [
                {
                    content: attachment,
                    filename: `${certificate.company.name}_Answers.pdf`,
                    type: "application/pdf",
                    disposition: "attachment"
                },
                {
                    content: fs.readFileSync(`./assets/images/Changemaker-Siegel.png`, { encoding: 'base64'}),
                    filename: "Changemaker",
                    type: "image/png",
                    content_id: "logo",
                    disposition: "inline"
                }
            ]
        };

        await sgMail.send(answerTemplate);
      } catch (error) {
        console.error(error);
    
        if (error.response) {
          console.error(error.response.body)
        }
      }
}

}

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The issue is that your logo attachment is not being sent as a base 64 string. You are reading the attachment as if its encoding is base 64, which is a different thing.

So, you have:

            content: fs.readFileSync(`./assets/images/Changemaker-Siegel.png`, {
              encoding: "base64",
            }),

But you need:

            content: fs.readFileSync(`./assets/images/Changemaker-Siegel.png`).toString("base64"),
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda