我有一个电子邮件脚本,从数据库中读取电子邮件,并将它们收集到一个巨大的对象。现在,这些电子邮件可以是BCC,CC,TO类型的电子邮件,必须通过各自类型的API传递给我们的电子邮件提供商。JavaScript的数组 - 确保每批有一定的元素
他们的API允许批量处理1000个电子邮件,这不是问题。问题是,在每个批次中,我必须至少有一个TO地址。换句话说,偶然一批批中有1000个'BCC'类型的电子邮件,而不是'TO'类型的电子邮件地址。这1000封电子邮件将不会被发送。当您处理20,000封电子邮件时,会创建20个批次,并且很可能会有一批包含所有BCC或CC类型电子邮件的批次,但都不是TO类型的地址。
所以我的问题是我怎样才能保证在处理过程中每个批次的TO地址?
一些代码与当前输出一起在下面。
while (addresses.length > 0) {
// I do some processing here. The addresses above is a map of emails that
// Something like: [ { label: 'to', address: '[email protected]' } ].
// Then the processing removes the individual labels from each email and slams
// them into one key value for each email type using a filter function. We also
// append some other things that must be separated as well like the recipient
// variables. The sent information looks like this to our email provider.
{
from: '[email protected]',
subject: 'fff',
text: 'fff',
to: ['[email protected]', '[email protected]'],
bcc: [],
* * // WHAT happens here if all the email addresses reside here and none above in the 'TO' label? The email will fail. The code must ensure at least one 'TO' type address in each batch of 1000.**
cc: [],
'recipient-variables': {
'[email protected]': {},
'[email protected]': {}
}
}
}
我最初的想法是随机化一些如何但不知道如何做到这一点。我认为在将电子邮件放入正确的插槽(IE类型的电子邮件)之前,您几乎必须对最初的阵列进行一些操作。建议?并感谢您花时间阅读我的问题。 :)
你确定你需要一个真正的'TO'吗?例如,Thunderbird让我只用BCC发送邮件,当我查看源代码时,我发现它内部发送了一个“To:undisclosed_recipients:”标头。 – CherryDT
是的。我把这个具体的问题带给了他们,他们说他们的系统在没有至少有一个地址的TO类型的情况下不会发送。 – Jay