我有一個電子郵件腳本,從數據庫中讀取電子郵件,並將它們收集到一個巨大的對象。現在,這些電子郵件可以是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