您好,
如何使用Web API v3通过一个API调用分别发送邮件,以便每个收件人在“收件人”框中只能看到其地址? 目前,我正在使用nodejs,Web API v3和sendgrid依赖关系发送邮件,但问题是用户在“收件人”框中获得了收件人的整个列表。 这是请求:
var request = sg.emptyRequest({
method: 'POST',
path: '/v3/mail/send',
body: {
personalizations: [
{
to: recepientEmails,
substitutions: emailTemplate.substitutions
}
],
from: {
email: '[email protected]',
name: 'Dorotea from AWW'
},
template_id: emailTemplate.template_id,
categories: emailTemplate.categories
}
});
我已经读过Web API v2,我将需要使用x-smtp标头,以便将电子邮件分别发送到表中第一行的每个收件人。
https://sendgrid.com/docs/API_Reference/Web_API/mail.html
而且我已经读到,使用SMTP的Web API v2中的所有内容都可以在此处仅使用一个请求就可以通过Web API v3完成。
https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/how_to_migrate_from_v2_to_v3_mail_send.html
最后,我想使用Web API v3进行一次API调用,以将电子邮件发送到多个地址,并希望每封电子邮件在TO标头中仅包含该收件人电子邮件。
一切顺利
兹沃尼米尔
嗨@ zvone187 ,
我不知道你是否已经找到了如何做到这一点,但是这看起来像你想要什么来实现的。
您应该为每个收件人添加不同的个性化设置。 它应在代码中转换为如下形式:
// This assumes every recipient gets the same substitutions. If not, just add the right substitution for each email
const personalizations = recipientEmails.map(email => ({
to: [{ email }],
substitutions: emailTemplate.substitutions
}));
const request = sg.emptyRequest({
method: 'POST',
path: '/v3/mail/send',
body: {
personalizations,
from: {
email: '[email protected]',
name: 'Dorotea from AWW'
},
template_id: emailTemplate.template_id,
categories: emailTemplate.categories
}
});
我不确定在一个请求中当前可以发送给的收件人数量的限制是多少。
@iamtheib感谢您的回复。 我从Sengrid得到了答案。 是的,这正是需要做的事情。
它可以工作,但是如何为不同的收件人发送不同的附件呢?
我需要为每个用户发送具有相同模板,不同个性化和不同附件文件的多封电子邮件。
最有用的评论
嗨@ zvone187 ,
我不知道你是否已经找到了如何做到这一点,但是这看起来像你想要什么来实现的。
您应该为每个收件人添加不同的个性化设置。 它应在代码中转换为如下形式:
我不确定在一个请求中当前可以发送给的收件人数量的限制是多少。