sendgridλ₯Ό node.js μ±κ³Ό ν΅ν©νκΈ° μν΄ API 3μ μ¬μ©νκ³ μμ΅λλ€. κΈ°λ³Έ μ΄λ©μΌμ΄ μλνμ§λ§ ν νλ¦Ώμ νΉμ νλͺ©μ λ°μ΄ν°λ‘ λ체ν΄μΌν©λλ€. μλλ μ΄λ©μΌμ 보λ΄λ λ° μ¬μ©νλ μ½λμ λλ€. μ΄λ©μΌμ΄ λκ°μ§ λ§ λμ²΄κ° μλνμ§ μμ΅λλ€.
var sg = require('sendgrid')('API-KEY');
var request = sg.emptyRequest();
request.body = {
"from": {
"email": "[email protected]",
"name": "Admin"
},
"personalizations" : [
{
"to": [
{
"email": recepientEmail,
"name": "User"
}
]
}
],
"subject": "This is subject",
"template_id": "template-id-here",
"substitution": {
"-sub1-": ["This is the new substitured text"],
"-sub2-": ["Substitured text"]
}
};
request.method = 'POST';
request.path = '/v3/mail/send';
sg.API(request, function(error, response) {
console.log(response.statusCode)
console.log(response.body)
console.log(response.headers)
});
μλ νμΈμ @ neeraj87 ,
μ΄ μμ κ° λμμ΄λκΈ°λ₯Ό λ°λλλ€ : https://github.com/sendgrid/sendgrid-nodejs/blob/master/use-cases/transactional-templates.md
λ¬Έμ κ° λ°μνλ©΄ μλ €μ£ΌμΈμ. κ°μ¬!
μλ νμΈμ @ neeraj87 ,
κ°λ¨ν λ§ν΄μ JSON ꡬ쑰λ μ¬μ€μ΄ μλλλ€.
λ체λ κ°μΈν λ°°μ΄ λ΄λΆμ μμ΄μΌν©λλ€. μ΄λ¬ν λ°©μμΌλ‘ κ° κ°μΈμ λν΄ μλ‘ λ€λ₯Έ λ체λ₯Ό μ μ ν μ μμ΅λλ€.
λν λ체 λ°°μ΄μ μ΄λ¦ (ν€)μ λ체 μ¬μΌνλ©° λ체 κ°μ λ¬Έμμ΄μ΄μ΄μΌν©λλ€. λ°°μ΄μ΄ μλλλ€.
"substitutions": {
"-sub1-": "This is the new substitured text",
"-sub2-": "Substitured text"
}
@thinkingserious λ¬Έμ λ§ν¬μ κ°μ¬λ립λλ€. λλ λν λ΄κ° λ체μμ 볡μν "s"λ₯Ό λΉ λ¨λ Έλ€λ κ²μ μμ μ±λ€.
@alperenozlu λ΅λ³μ κ°μ¬ λ리며 JSON ꡬ쑰μ ν€ κ° μμ μμ νμ΅λλ€.
@thinkingserious νλμ λΉ λ₯Έ μ§λ¬Έ, λ³μλ₯Ό μ¬μ©νμ¬ νκ·Έλ₯Ό λ체νλ €κ³ νμ§λ§ κ³μν΄μ λμκ² μ 곡λ©λλ€. μ€λ₯ : [{λ©μμ§ : 'μλͺ»λ μμ²', νλ : null, λμλ§ : null}]
var request = sg.emptyRequest();
request.body = {
"from": {
"email": "[email protected]",
"name": "Admin"
},
"personalizations" : [
{
"to": [
{
"email": recepientEmail,
"name": userNameVariable
}
],
"substitution": {
"-sub1-": variableB,
"-sub2-": variableA
}
}
],
"subject": "This is subject",
"template_id": "template-id-here"
};
request.method = 'POST';
request.path = '/v3/mail/send';
sg.API(request, function(error, response) {
console.log(response.statusCode)
console.log(response.body)
console.log(response.headers)
});
μ΄κ²μ λ΄κ° μ»λ μ€λ₯μ λλ€.
400
{μ€λ₯ : [{λ©μμ§ : 'μλͺ»λ μμ²', νλ : null, λμλ§ : null}]}
{μλ² : 'nginx',
λ μ§ : 'Thu, 01 Dec 2016 07:08:51 GMT',
'content-type': 'application / json',
'μ½ν
μΈ κΈΈμ΄': '63',
μ°κ²° : 'keep-alive'}
μλ νμΈμ @ neeraj87 ,
λ³μ μ νμ νμΈνμμμ€. μ νμ λ¬Έμμ΄μ΄μ΄μΌν©λλ€. λν λ체νλ λ체μ ν€λ₯Ό λ³κ²½νμμμ€.
@alperenozlu λΉμ μ΄ λ§μ΅λλ€, λ체 μ€ νλλ μ μμμ΅λλ€. κ·Έκ²μ λ¬Έμμ΄λ‘ λ³ννκ³ μλν©λλ€.
λμ μ£Όμ μ κ°μ¬ν©λλ€.
μλ
νμΈμ μ¬λ¬λΆ!
λ¬Έμμ΄ λμ κ° λ°°μ΄λ‘ λ체νλ €λ©΄ μ΄λ»κ²ν΄μΌν©λκΉ?
@Deniscapp λ λ°°μ΄ μμλ₯Ό μ½κ³ μ°κ²°νμ¬ λ¬Έμμ΄μ νμ± ν μ μμ΅λλ€.
@ neeraj87 κ·Έκ² λ΄κ° ν μΌμ
λλ€! κ·Έλ¬λ λλ κ·Έλ€μ΄ μ΄λ»κ² λ μ΄ κΈ°λ₯μ μΆκ°νλμ§ κΆκΈν©λλ€.
λ΅λ³ ν΄μ£Όμ
μ κ°μ¬ν©λλ€! :)
@Deniscapp μ£μ‘ν©λλ€, λͺ°λμ΅λλ€. λλ κ·Έκ²μ΄ μ΄μ λ²μ μ΄λΌκ³ μκ°ν©λλ€. SendGridμ "곡μμ μΈ"λκ΅°κ°κ°μ΄ μ§λ¬Έμ λ΅ν μ μμ΅λλ€.
@Deniscapp , @ neeraj87
API λ¬Έμμμ :
"substitution_tag": "λ체 ν κ°"ν¨ν΄μ λ°λ₯΄λ ν€ / κ° μμ λͺ¨μμ λλ€. λͺ¨λ λ¬Έμμ΄λ‘ κ°μ£Όλ©λλ€. μ΄λ¬ν λ체λ μ λͺ© λ° νμ λ§€κ° λ³μ μΈμλ μ΄λ©μΌ λ³Έλ¬Έμ ν μ€νΈ λ° html μ½ν μΈ μ μ μ©λ©λλ€.
λΌμ΄λΈλ¬λ¦¬μμ λ°°μ΄μ νμ©νκ³ μ΄λ₯Ό μ°κ²°νμ¬ μ₯λ©΄ λ€μμ λ¬Έμμ΄μ νμ±νλ κ²μ΄ μ μ© ν μ μμ΅λλ€.
@thinkingseriousκ° μΈκΈ ν μμ URLμ΄ μ½κ° λ³κ²½λ μ λ°μ΄νΈ : https://github.com/sendgrid/sendgrid-nodejs/blob/master/use-cases/transactional-templates.md
κ°μ¬ν©λλ€ @vaskort!
μλ λκΈμ λ§ν¬λ₯Ό μ λ°μ΄νΈνμ΅λλ€.
κ°μ₯ μ μ©ν λκΈ
@thinkingseriousκ° μΈκΈ ν μμ URLμ΄ μ½κ° λ³κ²½λ μ λ°μ΄νΈ : https://github.com/sendgrid/sendgrid-nodejs/blob/master/use-cases/transactional-templates.md