SendGridμ μ΄λ©μΌ λμ°λ―Έ μ νΈλ¦¬ν°λ₯Ό μ¬μ©νμ¬ ν νλ¦Ώ μ΄λ©μΌμ λ³΄λΈ ν. SendGrid APIμ μλ² μλ΅μ΄μ΄ λνΌ (sendgrid-nodejs)μ λ°λΌ μλͺ»λ JSONμ λ°νν©λλ€.
Uncaught SyntaxError: Unexpected token <
at Object.parse (native)
at node_modules/sendgrid/lib/sendgrid.js:110:42
at IncomingMessage.<anonymous> (node_modules/sendgrid/node_modules/sendgrid-rest/lib/client.js:108:9)
at endReadableNT (_stream_readable.js:921:12)
110 νμ λ€μκ³Ό κ°μ΅λλ€.
//Use callback
self.client.API(request, function(response) {
response.body = response.body ? JSON.parse(response.body) : response.body;
μ:
const BaseWelcomeEmail = (function(){
const helper = require('sendgrid').mail,
from_email = new helper.Email(testEmail),
to_email = new helper.Email(testEmail),
subject = "Welcome to Bedly",
content = new helper.Content("text/plain", "hello"),
mail = new helper.Mail(from_email, subject, to_email, content),
personalization = new helper.Personalization();
let substitution = new helper.Substitution(":firstname", "Aaron");
personalization.addSubstitution(substitution);
substitution = new helper.Substitution(":lastname", "Elk");
personalization.addSubstitution(substitution);
substitution = new helper.Substitution(":address", "96 Washington Avenue");
personalization.addSubstitution(substitution);
substitution = new helper.Substitution(":neighborhood", "Washington Heights");
personalization.addSubstitution(substitution);
substitution = new helper.Substitution(":unitNumber", "N/A");
personalization.addSubstitution(substitution);
substitution = new helper.Substitution(":roomNumber", "2J");
personalization.addSubstitution(substitution);
mail.addPersonalization(personalization);
return mail;
})();
mocha ν μ€νΈλ₯Ό λ§λ€ μλ μμ΅λλ€.μ΄ ν μ€νΈ νκ²½μμ μ€ννμ΅λλ€.
describe('Test Email Template', function () {
it('test template ${TEMPLATE_ID} is active and is complete', function (done) {
BaseWelcomeEmail.setTemplateId(TEMPLATE_ID);
SendEmailImpl.sendEmail(BaseWelcomeEmail.toJSON(), done, function(error, response){
assert_OKResponse(error, response, done);
});
});
});
sendEmail ν¨μμλ λ¬Έμμ μ€λͺ λλλ‘ APIλ₯Ό νΈμΆνκΈ°μν μΌλ°μ μΈ POST V3 μ€μ μ΄ ν¬ν¨λμ΄ μμ΅λλ€.
μλ νμΈμ @iamgollum ,
μκ°μλ΄μ΄ λ¬Έμ λ₯Ό μ μΆν΄ μ£Όμ μ κ°μ¬ν©λλ€! κ²ν λ₯Ό μν΄ λ°± λ‘κ·Έμ μΆκ°νμ΅λλ€.
ννΈ, μλ§λ μ΄κ²μ΄ λμμ΄ λ κ²μ λλ€ : https://github.com/sendgrid/sendgrid-nodejs/blob/master/USE_CASES.md#transactional_templates
κ°μ¬!
@iamgollum ,
μ¬μ ν λ¬Έμ κ° μμ΅λκΉ?
μ΄ λ¬Έμ κ° μμ΅λλ€. κ²μ ν λ§ν¬μμμ κ°μ΄ νΈλμμ ν νλ¦Ώμ μ¬μ©νκ³ μμ΅λλ€.
μ,μ΄ λ¬Έμ κ° κ΄λ ¨λμ΄ μλ€κ³ μκ°ν©λλ€ : https://github.com/sendgrid/sendgrid-nodejs/issues/347
μ΄ λ¬Έμ λ₯Ό λ²κ·Έλ‘ μ¬ λΆλ₯νκ³ ν¨κ» νμΈνκ² μ΅λλ€.
@adamsingle ,
ννΈ, μ¬ννλ λ° μ¬μ©ν μμλ μ½λ μνμ΄ μμ΅λκΉ? κ°μ¬!
@thinkingserious μ΄λ² μ£Όλ§μ μ½λ μνμ μ 곡νκ² μ΅λλ€. λλ μ§κΈ μ§μ₯μμ sendgridλ‘ λμμ€κ³ λͺ¨λ κ²μ λ€μ λ°©λ¬Έ ν κ²μ λλ€. μ§κ΅¬μμμ λ¨μ΄μ Έμ μ£μ‘ν©λλ€
Bah! μ΄ μ νν λ¬Έμ κ° λͺ μκ° λμ λ°μνμ΅λλ€. κ²½λ‘κ° μ ν μ¬λμμ λ―Όκ°νλ€λ κ²μ΄ λ°νμ‘μ΅λλ€.
var request = sendgrid.emptyRequest({
method: 'POST',
path: '/v3/mail/send',
body: mail.toJSON()
});
vs
var request = sendgrid.emptyRequest({
method: 'POST',
path: 'v3/mail/send',
body: mail.toJSON()
});
첫 λ²μ§Έ μ€ λν«μ μλνμ§λ§ λ λ²μ§Έ μ€ λν«μ json ꡬ문 λΆμ μ€λ₯λ₯Ό μ 곡ν©λλ€.
μ°λ¦¬λ μ€λ«λμ sendgrid κ³ κ° μ΄μμ§λ§ apiμμ΄ libλ₯Ό κ°μ§κ³ λκΈ° μμνμ΅λλ€. μλ§λμ΄ μΈλΆ μ¬νμ μ λ¬Έμνλμ΄ μκ³ κ°κ³Ό ν μ μ΄ μμ΅λκΉ? libλ₯Ό μλ΅νλ©΄ μλμΌλ‘ μ¬λμ μμ λΆλ κ²μ΄ μ’μ κ²μ λλ€.
@bradseefeld ,
μ²λ¦¬ν΄μΌν΄μ μ£μ‘ν©λλ€ :(
μ°λ¦¬λ μ΄λ¬ν λͺ¨λ μΈλΆ μ¬νμ μ¨κΈ°λ λ λμ λμ°λ―Έλ₯Ό μν΄ λ Έλ ₯νκ³ μμ΅λλ€. λ§€κ° λ³μμ λν΄ μ κ²½ μΈ νμκ° μμ΅λλ€.
https://github.com/sendgrid/sendgrid-nodejs/projects μμ νλ‘μ νΈλ₯Ό νλ‘μ° ν μ μμ΅λλ€.
κ°μ¬!
κ±±μ λ§. μ°λ¦¬λ μλΉμ€λ₯Ό μ’μν©λλ€!
μλ‘μ΄ λμ°λ―Έλ μ¬κΈ°μμ κ°λ° μ€μ λλ€ : https://github.com/sendgrid/sendgrid-nodejs/pull/378
κ°μ₯ μ μ©ν λκΈ
Bah! μ΄ μ νν λ¬Έμ κ° λͺ μκ° λμ λ°μνμ΅λλ€. κ²½λ‘κ° μ ν μ¬λμμ λ―Όκ°νλ€λ κ²μ΄ λ°νμ‘μ΅λλ€.
vs
첫 λ²μ§Έ μ€ λν«μ μλνμ§λ§ λ λ²μ§Έ μ€ λν«μ json ꡬ문 λΆμ μ€λ₯λ₯Ό μ 곡ν©λλ€.
μ°λ¦¬λ μ€λ«λμ sendgrid κ³ κ° μ΄μμ§λ§ apiμμ΄ libλ₯Ό κ°μ§κ³ λκΈ° μμνμ΅λλ€. μλ§λμ΄ μΈλΆ μ¬νμ μ λ¬Έμνλμ΄ μκ³ κ°κ³Ό ν μ μ΄ μμ΅λκΉ? libλ₯Ό μλ΅νλ©΄ μλμΌλ‘ μ¬λμ μμ λΆλ κ²μ΄ μ’μ κ²μ λλ€.