3

Node.js アプリケーションでSendGridを使用してメールを送信しています。私がpdfを添付しようとするすべての組み合わせは、添付されたpdfが読めなくなってしまいます。

私はもう試した:

fs.readFile('public_html/img/Report.pdf',function(err,data){
    var base64data = new Buffer(data).toString('base64');

    sendgrid.send({
        to        : hexDecode(_.e),
        from      : 'xxxxxxxxx@gmail.com',
        subject   : 'Report',
        
        files      : [{filename:'Report.pdf',content:'data:application/pdf;base64,'+base64data}],
        // files   : [{filename:'Report.pdf',contentType:'data:application/pdf',url:'public_html/img/'Report.pdf'}],
        // files   : [{filename:'Report.pdf',url:'public_html/img/'Report.pdf'}],
        html       : 'bla bla'

「PDFドキュメントの読み込みに失敗しました」を防ぐ方法を知っている人はいますか??

4

3 に答える 3

2

READMEによると、コンテンツをデータ URI に変換するのではなく、そのまま渡す必要があります。

fs.readFile('public_html/img/Report.pdf', function(err, data) {
    sendgrid.send({
        to        : hexDecode(_.e),
        from      : 'xxxxxxxxx@gmail.com',
        subject   : 'Report',

        files     : [{filename: 'Report.pdf', content: data}],
        html      : 'bla bla'
于 2013-07-16T14:46:45.900 に答える