如何使用 sendgrid 将 PDF 发送到电子邮件地址?

问题描述

我正在尝试使用以下代码发送 pdf

var html_to_pdf = require('html-pdf-node');
 var defer = Q.defer();
        let options = {format: 'A4',margin: {top: "20",left: "20",right: "20",bottom: "20"}};
        let html = "<p>Hi there,</p>";
        let file = {content: html};
        html_to_pdf.generatePdf(file,options).then(pdfBuffer => {
            var body = {
                subject: "Your",personalizations:
                    [{ to: [ { email: recipientEmail } ],"dynamic_template_data": {
                            "senderName": senderName,"name": recipientName,"email": recipientEmail,"body": recipientMessage,"subscriptionCode": subscriptionCode
                        }
                    }],to: [ { email: recipientEmail } ],from: { email: "[email protected]",name: "test Team" },content: [{type: "text/plain",value: "Hi there"}],attachments: [
                    {
                        filename: "test.pdf",content: btoa(pdfBuffer),type: 'application/pdf',disposition: 'attachment',}
                ]
            };
            this._sendEmail(body).then( (result) => {
                defer.resolve(result);
            }).catch (error => {
                defer.reject(error);
                console.error(error);
            });
        }).catch (error => {
            defer.reject(error);
            console.error(error);
        });
        return defer.promise;

不幸的是,pdf没有被发送?没有错误输出。我做错了什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)