2015-08-18 218 views
2

我試圖發送一個模板電子郵件郵戳在Node.js的郵戳:發送電子郵件模板

我創建的郵戳應用網站上的模板。我瀏覽過他們的文檔,但無法找到發送模板電子郵件的方法。

文檔來源:

http://blog.postmarkapp.com/post/125849089273/special-delivery-postmark-templates http://developer.postmarkapp.com/developer-api-templates.html

我已經嘗試了多種方法,包括:

client.emailWithTemplate("[email protected]", 
    "[email protected]",<template-id>, { 
    "link" : "https://example.com/reset?key=secret", 
    "recipient_name" : "Jenny" 
}); 

TypeError: Object # has no method 'emailWithTemplate'

client.sendEmail({ 
    "TemplateModel" : { 
     "customer_name" : "Jenny", 
    }, 
    "TemplateId" : 6882, 
    "From": "[email protected]", 
    "To": "[email protected]", 
}, function(error, success) { 
    if(error) { 
     console.log(error); 
    } else { 
     console.log(success); 
    } 
}); 

Console Log Error: { status: 422, message: 'A \'TemplateId\' must not be used when sending a non-templated email.', code: 1123 }

謝謝!

回答

4

我是node.js庫的當前維護者(以及從事郵戳模板的工程師之一)。

原始代碼段不起作用的可能原因之一是您可能使用舊版本的Postmark.js。我們在node.js包的1.2.1版本中添加了模板端點功能。

在您的項目的package.json文件中,您應該確保將其更新爲使用版本1.2.1或更高版本的postmark.js庫。如果您使用的是較舊版本的庫,則還需要運行npm update

另請注意,如果您在Postmark UI中單擊「編輯模板」,然後單擊「API片段」,UI將提供一個完整的語言片段(包括node.js)。

如果一切都失敗了,請聯繫支持,我們很樂意幫助您解決此問題。

+0

哇!沒有意識到這很簡單。我剛剛在幾天前得到了這個,但實際上它是1.0版本 - 現在我已經更新了,它的功能就像一個魅力。 – Lindsay

+1

非常感謝你澄清這一點! :) – Lindsay

+1

@Lindsay我很高興,謝謝你嘗試模板。我們認爲他們很棒。 –