【问题标题】:getting error while viewing pdf file in an email from postmark email attachment feature从邮戳电子邮件附件功能查看电子邮件中的 pdf 文件时出错
【发布时间】:2019-11-15 04:50:58
【问题描述】:

我不知道从内容字段中的邮戳附件功能发送电子邮件附件时要执行哪种编码。

我已经尝试了以下方法将pdf文件转换为base64但找不到工作:

fs.readFileSync("./filename.pdf").toString('base64')
////////
pdf2base64("./filename.pdf").then(
        (response) => {
            base= response //cGF0aC90by9maWxlLmpwZw==
        }
    ).catch(
        (error) => {
            console.log(error); //Exepection error....
        }
    )
/////
 function base64_encode(file) {
    // read binary data
    var bitmap = fs.readFileSync(file);
    // convert binary data to base64 encoded string
    return new Buffer.from(bitmap.toString('utf-8'),'base64');
}

我尝试发送电子邮件的代码如下:

var client = new postmark.ServerClient("*****");
  client.sendEmail({
    "From": "example@abc.com",
    "To": "abc@abc.com",
    "Subject": "Test",
    "TextBody": "please find attached file of your agreement",
    "Attachments": [
      {
        "Name":  'index.pdf',        
     "Content":fs.readFileSync("./filename.pdf").toString('base64'),
       "ContentType": "application/pdf"
      }
    ]
  }).then((result) => {
    console.log("the result is :", result)
  }).catch((err) => {
    console.log("error is : ", err)
  });

我只希望它找到如何根据此电子邮件附件的要求进行编码的方法。我应该在内容字段中输入什么来发送无错误的文件

【问题讨论】:

    标签: node.js base64 fs postmark


    【解决方案1】:

    您能就此与我们的支持团队联系吗?他们肯定能够提供帮助。 https://postmarkapp.com/contact

    【讨论】:

      猜你喜欢
      • 2012-12-12
      • 2013-12-29
      • 2014-05-23
      • 2023-03-07
      • 2020-03-26
      • 2016-11-30
      • 2012-05-23
      • 2013-03-17
      • 1970-01-01
      相关资源
      最近更新 更多