Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用Mailgun从Base64字符串发送pdf附件_Javascript_Meteor_Base64_Email Attachments_Mailgun - Fatal编程技术网

Javascript 使用Mailgun从Base64字符串发送pdf附件

Javascript 使用Mailgun从Base64字符串发送pdf附件,javascript,meteor,base64,email-attachments,mailgun,Javascript,Meteor,Base64,Email Attachments,Mailgun,我有一个由另一个函数生成的pdf,该函数返回Base64字符串。然后我想把它附加到一封邮枪电子邮件中,它是和。我看到有很多从附加文件的示例,但是我没有看到任何使用Base64的示例 我有一个方法生成Base64字符串并使用前缀进行合并,以便: //返回base64字符串:看起来像“YW55IGNhcm5hbCBwbGVhc3VyZQ=” const base64AttachmentString='数据:application/pdf;base64'+generatePDFSbase64(); 从

我有一个由另一个函数生成的pdf,该函数返回Base64字符串。然后我想把它附加到一封邮枪电子邮件中,它是和。我看到有很多从附加文件的示例,但是我没有看到任何使用Base64的示例

我有一个方法生成Base64字符串并使用前缀进行合并,以便:

//返回base64字符串:看起来像“YW55IGNhcm5hbCBwbGVhc3VyZQ=”
const base64AttachmentString='数据:application/pdf;base64'+generatePDFSbase64();
从“流星/电子邮件”导入{Email};
Email.send({
至:email@example.com",
摘自:“约翰·史密斯”,
主题:“以PDF格式发送Base64”,
html:generatedHTMLTemplate,
附件:base64AttachmentString
});

有没有办法发送Base64附件,让Mailgun将其识别为PDF?我知道这在和等其他邮件中是可能的。

流星的电子邮件似乎要求您添加
附件
键,这应该是一组附件

至于附件的选项-:

具体而言,在您的示例中,您可以使用:

const base64AttachmentString = 'data:application/pdf;base64,' + generatePdfBase64();

import { Email } from "meteor/email";

Email.send({
  to: "email@example.com",
  from: "John Smith <johnsmith@example.com>",
  subject: "Sending Base64 as PDF",
  html: generatedHTMLTemplate,
  attachments: [
    {
      path: base64AttachmentString
    }
  ]
});
constbase64attachmentstring='数据:application/pdf;base64'+generatePDFSbase64();
从“流星/电子邮件”导入{Email};
Email.send({
至:email@example.com",
摘自:“约翰·史密斯”,
主题:“以PDF格式发送Base64”,
html:generatedHTMLTemplate,
附件:[
{
路径:base64AttachmentString
}
]
});

在发送附件时,我是否需要包含任何多部分/表单数据编码?您肯定不需要。请检查并更新。它没有按原样工作-只是发送,没有附件。但是字符串正在记录。@maudulus,双重检查-请参阅AnswerTryed and Get中的更新:
TypeError:Path必须是字符串。收到
    {   // utf-8 string as an attachment
        filename: 'text1.txt',
        content: 'hello world!'
    },
    {   // binary buffer as an attachment
        filename: 'text2.txt',
        content: new Buffer('hello world!','utf-8')
    },
    {   // file on disk as an attachment
        filename: 'text3.txt',
        path: '/path/to/file.txt' // stream this file
    },
    {   // filename and content type is derived from path
        path: '/path/to/file.txt'
    },
    {   // stream as an attachment
        filename: 'text4.txt',
        content: fs.createReadStream('file.txt')
    },
    {   // define custom content type for the attachment
        filename: 'text.bin',
        content: 'hello world!',
        contentType: 'text/plain'
    },
    {   // use URL as an attachment
        filename: 'license.txt',
        path: 'https://raw.github.com/andris9/Nodemailer/master/LICENSE'
    },
    {   // encoded string as an attachment
        filename: 'text1.txt',
        content: 'aGVsbG8gd29ybGQh',
        encoding: 'base64'
    },
    {   // data uri as an attachment
        path: 'data:text/plain;base64,aGVsbG8gd29ybGQ='
    }
const base64AttachmentString = 'data:application/pdf;base64,' + generatePdfBase64();

import { Email } from "meteor/email";

Email.send({
  to: "email@example.com",
  from: "John Smith <johnsmith@example.com>",
  subject: "Sending Base64 as PDF",
  html: generatedHTMLTemplate,
  attachments: [
    {
      path: base64AttachmentString
    }
  ]
});