gpt4 book ai didi

node.js - 如何在node js中使用多个内容发送邮件?

转载 作者:太空宇宙 更新时间:2023-11-03 22:12:10 24 4
gpt4 key购买 nike

我正在使用 sendgrid 发送邮件。我可以从内容类型为 text/htmltext/Calendar 的任何人发送邮件,但我想同时发送两者。

这是我当前拥有的代码:

ics.createEvent(options, null, function(err, calendar) {
if (!err)
{
console.log('Event file', calendar);
var filePath = path.join('vabo_email', 'email.html');
fs.readFile(filePath, {encoding: 'utf-8'}, function(err, data) {
if (!err)
{
var helper = require('sendgrid').mail;
from_email = new helper.Email('booking@callvabo.com')
to_email = new helper.Email(email)
subject = subject
//Dynamic content
var tmp_data = data
fs.readFile(calendar, {encoding: 'utf-8'}, function(err, cal_data) {
if (!err)
{
var data = tmp_data.replace("$content", bodycontent).replace("$calendar", cal_data);
content = new helper.Content('text/html', data)
content = new helper.Content("text/Calendar", cal_data)

mail = new helper.Mail(from_email, subject, to_email, content);
var sg = require('sendgrid')('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');
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('mail send Successfully to', email);
}
else
{
console.log('Error for send mail', error);
}
});
}
});
}
else
{
console.log('Can not read calendar', err);
}
});
}
});

最佳答案

根据 sendgrid文档,这是必须完成的方式,无需帮助程序类。

content: [
{
type: 'text/html',
value: '<b>Hello, Email!'</b>,
},
],

所以很明显它是一个类型/数据对的数组

所以你们很多人尝试在没有帮助者的情况下发送,或者,您可以尝试这个,我不确定。

 content1 = new helper.Content('text/html', data)
content2 = new helper.Content("text/Calendar", cal_data)
final_content = [content1,content2]
mail = new helper.Mail(from_email, subject, to_email, final_content)

关于node.js - 如何在node js中使用多个内容发送邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39179374/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com