Sendgrid发送没有embedded代码的HTML电子邮件

我只想直接input我的HTML文件,input./blabla.html,而不是创build一个广告系列或模板。 有没有办法发送邮件没有把embedded式代码? 如果是这样,我会很高兴,谢谢! 我目前的代码如下所示:

var helper = require('sendgrid').mail from_email = new helper.Email("blabla@hotmail.com") to_email = new helper.Email("heyhey@gmail.com") subject = "Merhaba !" content = new helper.Content("text/plain", "selam") mail = new helper.Mail(from_email, subject, to_email, content) } var sg = require('sendgrid').SendGrid("mysecretapikey") var requestBody = mail.toJSON() var request = sg.emptyRequest() request.method = 'POST' request.path = '/v3/mail/send' request.body = requestBody sg.API(request, function (response) { console.log(response.statusCode) console.log(response.body) console.log(response.headers) }) 

       

网上收集的解决方案 "Sendgrid发送没有embedded代码的HTML电子邮件"

您可能需要更新您的sendgrid包。 一个基于你的需求的工作例子看起来像这样:

 var fs = require('fs'); var path = require('path'); var filePath = path.join(__dirname, 'myfile.html'); fs.readFile(filePath, {encoding: 'utf-8'}, function(err, data) { if ( ! err ) { var helper = require('sendgrid').mail; from_email = new helper.Email("blabla@hotmail.com"); to_email = new helper.Email("heyhey@gmail.com"); subject = "Merhaba !"; content = new helper.Content("text/html", data); mail = new helper.Mail(from_email, subject, to_email, content); var sg = require('sendgrid')('your api key'); var requestBody = mail.toJSON(); var request = sg.emptyRequest(); request.method = 'POST'; request.path = '/v3/mail/send'; request.body = requestBody; sg.API(request, function (error, response) { if ( ! error ) { console.log(response.statusCode); console.log(response.body); console.log(response.headers); } else { console.log(error); } }); } else { console.log(err); } }); 

myfile.html文件就在这个.js文件的旁边,看起来像这样:

 <html> <head> <title> Test </title> </head> <body> <h2> Hi! </h2> <p> This is a test email </p> </body> </html>