2016-01-26 27 views
3

我在Sendgrid中使用nodemailer(https://github.com/nodemailer/nodemailer-smtp-transport),我想每次向2000個用戶發送電子郵件,每個用戶的內容不同。目前,我創建一個SMTP傳輸並一次發送一封郵件,但我遇到了問題,我認爲只發送一個請求發送所有郵件會更好。
使用Sengrid SMTP API,可以通過使用替換標籤向具有定製內容的許多用戶發送郵件。在nodemailer中,是否可以使用它們在單個請求中向每個人發送自定義郵件?例如,使用setSubstitutions的sendgrid節點包(https://github.com/sendgrid/smtpapi-nodejs)是可能的,但我想繼續使用nodemailer。是否可以在nodemailer上使用Sengrid的Substitution標籤?

喜歡的東西:

smtp.sendMail({ 
     from: "Me", 
     to: [ "[email protected]", "[email protected]" ], 
     subs: { "-name-": [ "you", "him" ] }, 
     subject: "Your name", 
     html: "<h1>Your name is -name-</h1>" 
    }) 

這將是非常讚賞:)

回答

1

您應該能夠通過顯式設置必要的X-SMTPAPI頭做到這一點。

smtp.sendMail({ 
    headers: { 
    'X-SMTPAPI': '{"sub": { "-name-": ["you","him"] } }' 
    }, 
    from: "Me", 
    to: [ "[email protected]", "[email protected]" ],  
    subject: "Your name", 
    html: "<h1>Your name is -name-</h1>" 
}) 
+0

正是我需要的,謝謝! –

相關問題