λ€μ νμ΄λ‘λμμ 'μλͺ»λ μμ²'μ€λ₯κ° λ°μν©λλ€.
cosnt msg = {
"to": "[email protected]",
"from": "[email protected]",
"subject": "Support Pay Transparency at PayCheck",
"templateId": "24ae3147-4faa-4380-8613-c5be144f4542",
"customArgs": {
"ally_id": "cj6zlh7yd000001qir4r5suuk"
}
};
sgMail.send(msg)
{
"message": "Bad Request",
"code": 400,
"response": {
"headers": {
"server": "nginx",
"date": "Wed, 30 Aug 2017 22:30:41 GMT",
"content-type": "application/json",
"content-length": "365",
"connection": "close",
"access-control-allow-origin": "https://sendgrid.api-docs.io",
"access-control-allow-methods": "POST",
"access-control-allow-headers": "Authorization, Content-Type, On-behalf-of, x-sg-elas-acl",
"access-control-max-age": "600",
"x-no-cors-reason": "https://sendgrid.com/docs/Classroom/Basics/API/cors.html"
},
"body": {
"errors": [
{
"message": "Unless a valid template_id is provided, the content parameter is required. There must be at least one defined content block. We typically suggest both text/plain and text/html blocks are included, but only one block is required.",
"field": "content",
"help": "http://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/errors.html#message.content"
}
]
}
}
}
λ¬Έμμμλ templateId
μ΄μ§λ§ μ€λ₯ λ©μμ§μμλ template_id
μ
λλ€. λ λ€ μλνλλ° λμΌν μ€λ₯ λ©μμ§κ° λνλ©λλ€. sendgridμμ μ¬λ°λ₯΄κ² ꡬμ±λμλμ§ νμΈνκΈ° μν΄ ν
νλ¦Ώ νλ©΄μ μ€ν¬λ¦° μ·μ μ¨ μ μ± κ²μ¬λ‘ 첨λΆνμ΅λλ€.
@onesien μ λ
Έλ JS λ©μΌλ¬ APIλ λμ λ¬Έμλ₯Ό ꡬλΆνμ§ μμΌλ―λ‘ templateId
λλ template_id
λͺ¨λ μ¬μ©ν μ μμ΅λλ€. Camel μΌμ΄μ€λ JS λλμμ λ μΌλ°μ μ΄λ―λ‘ API μμ²΄κ° μ€λ€μ΄ν¬ μΌμ΄μ€λ₯Ό μ¬μ©νλ λμ μ΄μ λν μ§μμ μΆκ°νμ΅λλ€.
ν νλ¦Ώ IDμ μ΄λ€ μΌμ΄ μΌμ΄λλμ§ μ΄ν΄ λ³΄κ² μ΅λλ€.
μλ νμΈμ @onesien ,
μ§μν μ λ¬Έμ ν μλ μμ΅λλ€. λ¬Έμ κ° μ΄μ ν νλ¦Ώ νΈμ§κΈ°μ κ΄λ ¨μ΄ μλ€κ³ μκ°ν©λλ€.
μ ν νλ¦Ώμ λ§λ€κ³ ν΄λΉ IDλ₯Ό μ¬μ©ν΄ λ³Ό μλ μμ΅λκΉ?
λ§μμ λ΄μ,
Elmer
@thinkingserious λμμ μ΄κ²μ νμΈν μ μμ΅λκΉ? μμ²κ³Ό ν¨κ» template_id
λ§€κ° λ³μλ₯Ό μ¬λ°λ₯΄κ² 보λ΄λ κ² κ°μ΅λλ€. λ°©κΈ μ ν
νλ¦Ώμ λ§λ€μκ³ μ΄ λ¬Έμ λ λ°μν©λλ€.
@adamreisnz ,
λ΄ λ‘컬 ν μ€νΈκ° μλνμ§λ§ κ³μ μ μ ν νλ¦Ώ λ§ μμ΅λλ€.
λ€μ νμΈνκ² μ΅λλ€
μλμ, μλ‘ λ§λ μ ν νλ¦Ώμ μ¬μ©νμ¬ λμΌν λ¬Έμ κ° λ°μνμ΅λλ€.
λ€μμ μ¬κΈ° μ μλ₯Ό λ°λ₯΄λ λλ₯Ό μν΄ (λ²μ v6.1.1 μ¬μ©) μλν©λλ€.
// Setup sendgrid api
const sendGridMail = require('@sendGrid/mail');
sendGridMail.setApiKey(process.env.SENDGRID_API_KEY);
sendGridMail.setSubstitutionWrappers('-', '-');
//build object
var mailOptions = {
personalizations:[{
to: '[email protected]',
substitutions: {'name':'John', 'city':'Denver'}
}],
from: '[email protected]',
reply_to: '[email protected]',
subject: 'Hello',
html: 'email text goes here',
templateId: '13b8f94f-bcae-4ec6-b752-70d6cb59f932'
};
//send
sendGridMail.send(mailOptions);
μ, APIκ° λͺ¨λ κ²½μ°μ μ½ν μΈ λΈλ‘μ μꡬνλ μ€λλ λ²κ·Έκ° μ¬ ν¬μ₯ λ κ² κ°μ΅λλ€. κ·Έλμ μ΄κ²μ μλν©λλ€.
// Setup sendgrid api
const sendGridMail = require('@sendGrid/mail');
sendGridMail.setApiKey(process.env.SENDGRID_API_KEY);
sendGridMail.setSubstitutionWrappers('-', '-');
//build object
var mailOptions = {
to: '[email protected]',
from: '[email protected]',
reply_to: '[email protected]',
subject: 'Hello',
templateId: '13b8f94f-bcae-4ec6-b752-70d6cb59f932',
html: ' ',
substitutions: {
name: 'Some One',
city: 'Denver',
}
};
//send
sendGridMail.send(mailOptions);
νμ§λ§ μ΄κ±΄ μλλλ€ :
// Setup sendgrid api
const sendGridMail = require('@sendGrid/mail');
sendGridMail.setApiKey(process.env.SENDGRID_API_KEY);
sendGridMail.setSubstitutionWrappers('-', '-');
//build object
var mailOptions = {
to: '[email protected]',
from: '[email protected]',
reply_to: '[email protected]',
subject: 'Hello',
templateId: '13b8f94f-bcae-4ec6-b752-70d6cb59f932',
substitutions: {
name: 'Some One',
city: 'Denver',
}
};
//send
sendGridMail.send(mailOptions);
λ΄λΆ νμΈ μ€ ...
ν νλ¦Ώμ 보λ΄λ €λ©΄ μ½ν μΈ λΈλ‘μ μΆκ°ν΄μΌνμ΅λλ€. μ html νΈμ§κΈ°μμ λ§λ ν νλ¦Ώμ μ¬μ©νλ λμ _Bad Request (400) "μ ν¨ν template_idκ° μ 곡λμ§ μμΌλ©΄ μ½ν μΈ λ§€κ° λ³μκ° νμν©λλ€. μ μ λ μ½ν μΈ λΈλ‘μ΄ νλ μ΄μ μμ΄μΌν©λλ€ ..."_.
sgMail.setApiKey(sgKey);
sgMail.setSubstitutionWrappers('-', '-');
var msg: any = {
to: email,
from: '[email protected]',
templateId: 'xxxxxxx',
substitutions: {
verifyUrl: createAccountLink
}
};
sgMail.send(msg)
μ½ν μΈ λΈλ‘μ μΆκ°νλ©΄ ν νλ¦Ώ μ΄λ©μΌμ΄ html νΈμ§κΈ°μμ νμν λλλ‘ μ μ‘λ©λλ€.
sgMail.setApiKey(sgKey);
sgMail.setSubstitutionWrappers('-', '-');
var msg: any = {
to: email,
from: '[email protected]',
content: [{"type":"text/html","value":"0"}],
templateId: 'xxxxxx',
substitutions: {
verifyUrl: createAccountLink
}
};
sgMail.send(msg)
μ’μμ, λ²κ·Έλ‘ μ΄μ΄ λκ² μ΅λλ€.
λ΄ μκ° μμ΄ SDKλ μ€μ λμ§ μμ κ²½μ° λΉ μ½ν μΈ κ°μ²΄λ₯Ό μΆκ°νκ³ μμ΅λλ€. htmlκ³Ό txtκ° μ€μ λμ§ μμ κ²½μ° μ΄λ¬ν κΈ°λ₯ μ 건λ λΈ νμκ° μλ€κ³ μκ°ν©λλ€.
μ§κΈμ μμ ν΄κ²° λ°©λ²μ΄ νμν μμ μ μνν©λλ€.
@thinkingserious λλ λΉμ μ΄ μ³λ€κ³ μκ°ν©λλ€. API λ¬Έμλ₯Ό μ½κ³ νλκ° νμλΌκ³ μκ°νμ΅λλ€. λ΄κ° λμΉ μ μ¨κ²¨μ§ μ£Όμ (λλΌμ΄ μ€νμΌμ λλ€!) λ§ μμ΅λλ€.
λλ μ΄κ²μ ν΄κ²°νκΈ° μν΄ PRμ λ§λ€ κ²μ λλ€!
ν€ν€, μλ΄ κ°μ¬ν©λλ€!
PRμ΄ μλ μ€μ λλ€. μ΄λ κ²νλ©΄ λ¬Έμ κ° ν΄κ²°λκ³ μ 곡λ μ½ν μΈ κ°μλ κ²½μ° μμ²κ³Ό ν¨κ» μ½ν μΈ νλλ₯Ό 보λ΄μ§ μμ΅λλ€.
λμ μ£Όμ μ κ°μ¬ν©λλ€. λλ λ§ κ·Έλλ‘ μ μ μ μκ³ μμλ€. λλ λ§μΉ¨λ΄ μ΄μ ―λ°€ λ¦κ² ν΄κ²° λ°©λ²μ μμ λκ³ λ λ§μ μ 보λ₯Όλ³΄κ³ νκΈ° μν΄ μ¬κΈ°μ μμ§λ§ λͺ¨λκ° μ΄λ―Έ κ·Έκ²μ λν΄ μκ³ μλ κ² κ°μ΅λλ€ :-)
@onesien μ λν΄ μ£μ‘ν©λλ€.
μμ μ¬νμ΄ npm (v6.1.2)μ λ°©κΈ νΈμλμμ΅λλ€.
@thinkingserious μ μλ΅μμ κ·Έλλ‘ μ½λλ₯Ό μ¬μ©νμΌλ©° μ¬μ ν λ¬Έμ κ° λ°μνμ΅λλ€.
λλ sengridμμ λ§λ ν
νλ¦Ώμμ κ°μ₯ κΈ°λ³Έμ μΈ λ체λ₯Ό μ»μΌλ €κ³ ν©λλ€. CloudWatchμ μλ΅ (Lambdaμμ μ€ν μ€μ΄λ―λ‘)μ 202λ‘ νμλμ§λ§ μμ ν μ΄λ©μΌμ A message was received from this address by our systems that had errors in the smtpapi header, and cannot be processed. The error detected was: The template id must be a valid template id for your account.
μ¬κΈ°μ λ΄κ° λ μλͺ»νκ³ μλ? λλ sendgrid λ¬Έμλ₯Ό μ΄ν΄ λ³΄λ €κ³ λ Έλ ₯νκ³ μμ§λ§ λͺ¨λ κ²μ΄ μ λ§ λ¨νΈμ μ΄λΌκ³ λλλλ€.
ν νλ¦Ώ IDλ₯Ό μ΄λ»κ² 보λ΄λμ? λλ€κ° νΈμΆ λ λ νκ²½ λ³μλ₯Ό ν΅ν©λκΉ?
@cbilliau μ λΉ λ₯Έ λ΅μ₯μ κ°μ¬λ립λλ€. μ κ²½μ°μλ ν νλ¦Ώ λ¬Έμμ΄μ΄ νλ μ½λ©λμ΄ μμ΅λλ€. λ΄ μλ λ€μκ³Ό κ°μ΅λλ€.
const sgMail = require("@sendgrid/mail");
sgMail.setApiKey(
"XXXXX"
);
sgMail.setSubstitutionWrappers("%", "%"); // Configure the substitution tag wrappers globally
const msg = {
to: formFields.toEmail,
from: formFields.fromEmail,
subject: "Hello world",
text: "test",
html: "<p>test</p>",
templateId: "be2cc0da-5b2c-428f-8e45-c140f6cfb6eb",
substitutions: {
name1: formFields.fromName,
name2: formFields.fromName,
date: formFields.date
}
};
sgMail.send(msg);
@tetreault μμ λλ΅μ νμΈνκ³ content: [{"type":"text/html","value":"0"}],
λ₯Ό λ΄ κΈ°λ₯μ μΆκ°νλ©΄ μλνμ΅λλ€. μ΄μ λ₯Ό μ μ μμ΅λλ€.
λ°©κΈ μλνμ§λ§ λΆννλ @cbilliau :(. λμΌν μ΄λ©μΌμ λ€μ
A message was received from this address by our systems that had errors in the smtpapi header, and cannot be processed.
The error detected was: The template id must be a valid template id for your account. You provided be2cc0da-5b2c-428f-8e45-c140f6cfb6eb
μμ° @cbilliau μ μ μ μνμ π€£ λλ λ¨μ§ 물건μ ν΅ν΄ μλλ₯΄κ³ μμκ³ λ λ§μ κ΄μ¬μ κΈ°μΈμ΄μ§ μμμ΅λλ€. λλ λ΄κ° "λ§μΌν "μμ λ§λ ν νλ¦Ώμ κ³ μ IDλ₯Ό μ‘μμ§λ§ "νΈλμμ ν νλ¦Ώ"μμκ° μλλΌλ κ²μ κΉ¨λ¬μλ€. λλ sendgrid UIλ₯Ό λ§μ΄ μ¬μ©νμ§ μκ³ μμ ν λ§κ°μ‘μ΅λλ€.
μ 체 μΌκ΅΄ μλ°λ₯, λ΄ λ λΆλΆμ κ³ μ νκ³ μλνκΈ°λ₯Ό λ°λλλ€.
kk-νΉν @cbilliauκ° μΈκΈ ν content: [{ type: "text/html", value: "0" }]
μ€μ μ¬μ©νμ¬ μ§κΈ μλνλμ§ νμΈν©λλ€ π
κ°μ₯ μ μ©ν λκΈ
λμ μ£Όμ μ κ°μ¬ν©λλ€. λλ λ§ κ·Έλλ‘ μ μ μ μκ³ μμλ€. λλ λ§μΉ¨λ΄ μ΄μ ―λ°€ λ¦κ² ν΄κ²° λ°©λ²μ μμ λκ³ λ λ§μ μ 보λ₯Όλ³΄κ³ νκΈ° μν΄ μ¬κΈ°μ μμ§λ§ λͺ¨λκ° μ΄λ―Έ κ·Έκ²μ λν΄ μκ³ μλ κ² κ°μ΅λλ€ :-)