๋ณ๊ฒฝํ์ง ์๊ณ ํธ๋์ญ์ ์ด๋ฉ์ผ์์ ๋์ฒด๋ฅผ ์ฌ์ฉ ํ๋
test.js
์ ์์ ํ์ฌ API ํค, ์ด๋ฉ์ผ ์ฃผ์ ๋ฐ ์์์ ๋ง๋ templateId
์ ์ฝ์
ํฉ๋๋ค.node test.js
ํฉ๋๋ค.์๋ ํ์ธ์ @panayi ,
ํ์ธํด์ผ ํ ์ฌํญ :
HTML์ด ์ด๋ป๊ฒ ์๊ฒผ๋์ง ๊ณต์ ํ ์ ์์ต๋๊น?
๊ฐ์ฌ!
๋ง์์ ๋ด์,
Elmer
์๋
ํ์ธ์, @thinkingserious , @panayi๊ฐ ์ธ๊ธ ํ ๊ฒ๊ณผ ๋์ผํ ๋ฌธ์ ๋ฅผ ์ฌํ ํ ์์์์ต๋๋ค.
๋ด Html ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
์๋ ํ์ธ์ first_name (์ง์ : employee_id)
์ผ๋ถ HTML ์ฝ๋
์ํธ
sgMail.setApiKey('apikey');
sgMail.setSubstitutionWrappers('{{', '}}'); // Triied sgMail.setSubstitutionWrappers('-', '-'); as well`
const msg = {
to: '[email protected]',
from: '[email protected]',
subject: 'Hello world',
text: 'Hello plain world!',
html: 'Hello HTML world!',
templateId: 'template-id',
substitutions: {
first_name: 'Tejas',
employee_id: 'emp123',
},
};
sgMail.send(msg);
์ฐธ๊ณ : substitutionWrappers: ['{{', '}}']
๋ ์ฌ์ฉํด ๋ณด์์ต๋๋ค.
๋ฉ์์ง ๋ด์์ ๊ทธ๋ฌ๋ ์ด์ด ์์ต๋๋ค.
๊ธฐ์ ์ ์ธ๋ถ ์ฌํญ:
์ด ๋ฌธ์ ์ ๋ง์ ์๊ฐ์ ํฌ์ ํด ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค.
์๋ ํ์ธ์ @tjstlekr ,
HTML ์ฝ๋์์ first_name
์ {{first_name}}
ํ๊ณ employee_id
์ {{employee_id}}
.
๊ฐ์ฌ!
๋ง์์ ๋ด์,
Elmer
์๋
ํ์ธ์ @thinkingserious ,
HTML ์ฝ๋ ๋ ํ
ํ๋ฆฟ ์ฝ๋๋ฅผ ์๋ฏธํฉ๋๊น?
์ฌ๊ธฐ ์์ ์์ฒญ ๋ณธ๋ฌธ์ ์ง์ ํ๋ฉด ๋์ฒด ํ๊ทธ๊ฐ ์ ๋๋ก ์๋ํ์ง๋ง ํ์ด์ง ์์ ๋ฏธ๋ฆฌ ์ ์ ๋ ์์ ๋ฅผ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ์๋ ์๋ํ์ง ์๋ ์ด์ ๋ ๋ฌด์์
๋๊น?
๊ฐ์ฌ!
์ @tjstlekr , ์ด ์์ ์ ์ค๋ช ๋ ํ ํ๋ฆฟ ์ฝ๋๋ฅผ ์๋ฏธํฉ๋๋ค.
๊ตฌ์ฒด์ ์ธ ์๊ฐ ์์ผ๋ฉด ๋ ๋ฒ์งธ ์ง๋ฌธ์ ๋ตํ ์ ์์ต๋๋ค. (์ : ์์ฒญ ๋ณธ๋ฌธ ๋ฐ ํ ํ๋ฆฟ ์ฝ๋).
๋ง์์ ๋ด์,
Elmer
์ฌํ๊ฒ! ํ
ํ๋ฆฟ ์ฝ๋์ ๋ํ ์ก์ธ์ค ๊ถํ์ด ์์ต๋๋ค. ๋ค๋ฅธ ๋ฒ์ ์ ๊ณ ์ํ๊ฒ ์ต๋๋ค.
์ด์จ๋ ๊ฐ์ฌํฉ๋๋ค @thinkingserious
์๋ํด ๋ณด์ จ์ต๋๊น?
substitutions: {
'first_name': 'Tejas',
'employee_id': 'emp123',
},
์, @thinkingserious๊ฐ ์๋ํ์ต๋๋ค. ๋๋ ๋ํ ๋ค์๊ณผ ๊ฐ์ ๋ฐฉ๋ฒ์ ์๋ํ์ต๋๋ค
substitutions: {
'-first_name-': 'Tejas',
'-employee_id-': 'emp123',
},
substitutions: {
'%first_name%': 'Tejas',
'%employee_id%': 'emp123',
},
substitutions: {
'=first_name=': 'Tejas',
'=employee_id'=: 'emp123',
},
@tjstlekr ,
๋๋ ๋น์ ์ ํด๊ฒฐ์ฑ ์ ๋๊ตฌ๋ ์ง ๋์ฒด ๋ฌธ์๋ก ๋ณ์๋ฅผ ๋ํํ๊ธฐ ์ํด HTML ํ ํ๋ฆฟ ์ฝ๋๋ฅผ ๋ณ๊ฒฝํ ์์๋ ์ฌ๋์ ์ป๋ ๊ฒ์ด๋ผ๊ณ ์๊ฐํฉ๋๋ค.
๋ง์์ ๋ด์,
Elmer
@thinkingserious ๊ฐ ๋ง์ต๋๋ค. ํ ํ๋ฆฟ ๋ณ์๋ ๋ฐ๋์ ์ด์ค ๋๊ดํธ {{name}}๋ก ๋ฌถ์ด์ผํฉ๋๋ค. ๊ทธ๋ ์ง ์์ผ๋ฉด SendGrid๋ ๋น์ ์ด ๋ณด๋ธ ๋์ฒด๋ฌผ์ ์ด๋์ ๋์ ์ง ์ ์ ์์ต๋๋ค.
๋ณ์์ ์ด์ค ๋๊ดํธ๊ฐ ์ ๋ง ํ์ํฉ๋๊น? ๋๋ ๊ณ์ํด์ ์๋ํด ๋ณผ ๊ฒ์ด์ง๋ง ๊ฐ์ ์ฌ๋์ ๋ค๋ฅธ ๊ฒ์๋ฌผ์ ์ด์ค ๋๊ดํธ๊ฐ ์๋ ๋์๋ก ์๋ํ๋ ๋์ฒด๋ฅผ ๋ณด์ฌ์ฃผ์์ต๋๋ค.
์๋ ํ์ธ์ @tetreault ,
๊ธฐ๋ณธ์ ์ผ๋ก ์ด์ค ๋๊ดํธ๋ฅผ ์ฌ์ฉํฉ๋๋ค. setSubstitutionWrappers
์์๋ ์์ฐ ํ๋๋ก ์์ ํ ์ ์์ต๋๋ค.
๊ฐ์ฌ!
๋ง์์ ๋ด์,
Elmer
@panayi ์ ๊ฐ์ ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ต๋๋ค.
ํธ๋์ญ์ ํ ํ๋ฆฟ ์ํ์ ๋ฐ๋์ต๋๋ค. ๋์ฒด ๋ํผ๋ฅผ ์ค์ ํ๊ณ ํ ํ๋ฆฟ์์ ์ด์ค ๋๊ดํธ๋ก ๋์ฒด๋ฅผ ๋ํํ์ต๋๋ค. ๊ทธ๋ฌ๋ ๋ด๊ฐ๋ฐ์ ์ด๋ฉ์ผ์ ๋ด๊ฐ ์ ๊ณต ํ ๊ฒ์ผ๋ก ๋์ฒดํ์ง ์๊ณ ๋ชจ๋ ๋์ฒด ํญ๋ชฉ์ ์ ๊ฑฐํ์ต๋๋ค.
ํ ํ๋ฆฟ์ ๋ํด ์ฝ๋ ํธ์ง๊ธฐ์ ๋์์ธ ํธ์ง๊ธฐ๋ฅผ ๋ชจ๋ ์ฌ์ฉํด ๋ณด์์ต๋๋ค.
๊ธฐ์ ์ ์ธ๋ถ ์ฌํญ:
๊ฐ์ฌ!
@nrator ๋ , ์๋ ํ์ธ์.
๋์ฒด๊ฐ ๋น ๋ฌธ์์ด๋ก ๋ฐ๋๋ฉด ๋ฐ๋ณตํ๋ ๋ณ์๊ฐ ๋น์ด ์์ง ์์์ง ๋ค์ ํ์ธํฉ๋๋ค. ๋น์ด ์์ง ์์์ง ํ์ธํ ๊ฒฝ์ฐ ๊ด๋ จ HTML๊ณผ ํจ๊ป ์ฝ๋ ์ค ๋ํ์ ๊ณต์ ํ์ฌ ์๋ํ๊ณ ์ฌํ ํ ์ ์์ต๋๊น?
๊ฐ์ฌ!
๋ง์์ ๋ด์,
Elmer
์๋ ํ์ธ์ @thinkingserious
๋๋ ๋ณ์๊ฐ ์๋๋ผ ๋ฌธ์์ด์ ์ฌ์ฉํ๊ณ ์์ผ๋ฏ๋ก ๋น์ด ์์ง ์์ต๋๋ค. ๋ค์์ ์ฝ๋ ์ค ๋ํซ, HTML ๋ฐ ๊ฒฐ๊ณผ์ ๋๋ค.
์ํธ
const sgMail = require("@sendgrid/mail");
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
sgMail.setSubstitutionWrappers("{{", "}}"); // Configure the substitution tag wrappers globally
const msg = {
from: "[email protected]", // my personal email
to: "[email protected]", // my another personal email
subject: "Hello world",
text: "Hello plain world!",
html: "<p>Hello HTML world!</p>",
templateId: "d-27e7d954368c46519eddc806e5cf8156",
substitutions: {
name: "Some One",
city: "Denver"
}
};
sgMail.send(msg).catch(err => console.error(err.message));
HTML ํ ํ๋ฆฟ
<html>
<head>
<title></title>
</head>
<body>
Hello {{name}},
<br /><br/>
I'm glad you are trying out the template feature!
<br /><br/>
<%body%>
<br /><br/>
I hope you are having a great day in {{city}} :)
<br /><br/>
</body>
</html>
๋ฐ์ ์ด๋ฉ์ผ
Hello ,
I'm glad you are trying out the template feature!
<%body%>
I hope you are having a great day in :)
๊ธฐ์ ์ ์ธ๋ถ ์ฌํญ
sendgrid-nodejs ๋ฒ์ : @ sendgrid / [email protected]
Node.js ๋ฒ์ : 8.11.2
์น์ ํ๋,
์ ์ด์จ
์๋
ํ์ธ์, ํธ๋์ญ์
ํ
ํ๋ฆฟ๊ณผ ๋์ผํ ๋ฌธ์ ๊ฐ ์์ต๋๋ค. ๋ณ์๋ ํฝ์
๋์ง ์์ต๋๋ค. ํ
์คํธ ๋ฐ์ดํฐ๋ฅผ ์ฌ์ฉํ์ฌ SG ๋์ ๋ณด๋์์ ํ
ํ๋ฆฟ์ ๋ฏธ๋ฆฌ ๋ณด๋ฉด ๋ชจ๋ ๊ฒ์ด ์ฌ๋ฐ๋ฅด๊ฒ ๋ณด์
๋๋ค.
๋๋ฝ ๋ ๋ณ์ ๊ฐ์ ์ ์ธํ๊ณ ์ฌ๋ฐ๋ฅธ ํ
ํ๋ฆฟ๊ณผ ํจ๊ป ์ฌ๋ฐ๋ฅธ ์ฌ๋์๊ฒ ์ด๋ฉ์ผ์ด ์ ์ก๋ฉ๋๋ค.
์ดํ ์ ์ ์ ์๋ํ๋ ๋ ๊ฑฐ์ ํ
ํ๋ฆฟ์ ๋ง๋ค์๊ณ ์ค๋์ ์ต์ ํ
ํ๋ฆฟ์ผ๋ก ์ ํํ์ต๋๋ค.
ํธ๋์ญ์
ํ
ํ๋ฆฟ๊ณผ ์๋ํ์ง ์์ต๋๋ค. ์ด์ ๋ ๊ฑฐ์ ํ
ํ๋ฆฟ์ ๋ณต์ ํ์ต๋๋ค.
์ ์๋ํฉ๋๋ค.
"@ sendgrid / mail": "6.3.1"| Node.js 8.10
๋ด ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
async function sendEmail({ email, firstName, password }) {
const msg = {
to: [{ email, firstName }],
from: {
email: "[email protected]",
name: "name"
},
asm: {
group_id: 1234
},
templateId: "d-64b15a042b2d41d7a4b5b6a4eea649c5",
substitutions: {
userName: firstName,
email,
password
}
}
try {
await sgMail.send(msg);
} catch(e){
e.message
}
};
๋ค์์ html ํ ํ๋ฆฟ์ ๋๋ค.
<h3>Hi {{userName}},</h3>
<div><span style="font-size:16px;">Your account has been setup. To login please use</span></div>
<div><span style="font-size:16px;">the credentials below.</span></div>
<div> </div>
<div><span style="font-size:16px;"><strong>Email:</strong> {{email}}</span></div>
<div><strong><span style="font-size:16px;">Password: </span></strong><span style="color: rgb(0, 0, 0); font-family: arial; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400;">{{password}}</span></div>
<div><span style="font-weight: 600; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-family: arial; font-size: 14px; color: rgb(0, 0, 0);"><span style="font-size: 16px;">SignIn Url: <a href="https://a.abc.com">https://a.abc.com/</a></span></span></div>
<div> </div>
<div> </div>
<div><span style="font-size:16px;">Please let us know if you need any help, email us at <a href="mailto:[email protected]">[email protected]</a></span></div>
๊ฑด๋ฐฐ
๋ฐฉ๊ธ ๋์ผํ HTML ์ฝ๋๋ก ๋ ๊ฑฐ์ ํ ํ๋ฆฟ์ผ๋ก ์ ํํ๋๋ฐ ์๋ํฉ๋๋ค. V3 API์ ์๋ก์ด ๋ณ๊ฒฝ ๋๋ฌธ์ผ ์ ์์ต๋๊น?
์๋ ํ์ธ์, @himanshupnt ์ ์๊ฒฌ์ ์ฝ์ ํ ๋ ๊ฑฐ์ ํ ํ๋ฆฟ์ผ๋ก ํ ์คํธํ์ผ๋ฉฐ ์๋ํ์ต๋๋ค. ๊ฐ์ฌํฉ๋๋ค @himanshupnt .
๋์ค์ Sendgrid ๋ฌธ์ Mail Send with Dynamic Transactional Templates ๋ฅผ ์ฐพ์์ต๋๋ค. ์ ํ ํ๋ฆฟ (๋ ๊ฑฐ์ ํ ํ๋ฆฟ์ด ์๋)์ด ์๋ํฉ๋๋ค. ๋์ผํ HTML ํ ํ๋ฆฟ์ ์ฌ์ฉํ๊ณ ์ฝ๋๊ฐ ๋ค์๊ณผ ๊ฐ์ด ์ ๋ฐ์ดํธ๋์์ต๋๋ค.
const sgMail = require("@sendgrid/mail");
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
sgMail.setSubstitutionWrappers("{{", "}}"); // Configure the substitution tag wrappers globally
const msg = {
from: "[email protected]",
templateId: "d-27e7d954368c46519eddc806e5cf8156",
personalizations: [
{
to: [
{
email: "[email protected]"
}
],
dynamic_template_data: {
name: "Someone",
city: "Somewhere",
subject: "Hello new world"
}
}
]
};
sgMail.send(msg).catch(err => console.error(err.message));
"substitutions"๋ฅผ "dynamic_template_data"๋ก ๋ฐ๊พธ๊ณ ๋ฌธ์์์ ์๊ตฌํ๋๋๋ก "personalizations"์ "to"๋ฅผ ๋ฐฐ์นํ์ต๋๋ค. ๋ํ ์ฃผ์ ๋ฅผ "dynamic_template_data"์ค ํ๋๋ก ์ทจ๊ธํ๊ณ ์๋ํฉ๋๋ค. (ํ ํ๋ฆฟ ์ ๋ชฉ ํ๋์ {{subject}} ์ ๋ ฅ)
๊ฐ์ฌ.
@nrator ์ ๋ ๊ทธ๋ ๊ฒํ์ต๋๋ค. ๊ฒ์ ํด ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค!
๋๋ ๊ฐ์ ๋ฌธ์ ๊ฐ ์๊ณ ๋ฌธ์ ๋ ์ด์์ต๋๋ค (์ฒ์์ ์ธ๊ธ ๋ ํด๊ฒฐ์ฑ
์ ์๋ํ ํ). ๊ทธ๋ฌ๋ @nrator์์ ์ธ๊ธ ํ ๋ค์ ํ
ํ๋ฆฟ์ name
๋ฐ city
๋ฅผ ์ถ๊ฐ ํ ์์์์ต๋๋ค. ๊ทธ๋ฌ๋ <%subject%>
๋ฐ <%body%>
๋ ๋ด๊ฐ๋ฐ์ ์ด๋ฉ์ผ์ ํฌํจ๋์ด ์์ผ๋ฏ๋ก ๋์ฒด ํ ์ ์์ต๋๋ค. <%body%>
๋ฐ <%subject%>
๋์ฒดํ๋ ค๋ฉด ์ด๋ป๊ฒํด์ผํฉ๋๊น? @himanshupnt ์ด๋ป๊ฒ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐ ํ์ต๋๊น?
์๋ ํ์ธ์ @ pankaja92 , <% subject %>๋ ์๋ํ์ง ๋ชปํ์ต๋๋ค. ์ด์ ์ฃผ์ ๋ฅผ ๋ค๋ฃจ๋ ๋ฐฉ์์ "dynamic_template_data"์ค ํ๋๋ก ์ทจ๊ธํฉ๋๋ค. ์ฆ, <% %> ๋์ {{}}๋ก ๊ฐ์ธ๊ณ "dynamic_template_data"๋ด์์ ์ฒ๋ฆฌํฉ๋๋ค.
๋์์ด ๋ ์์๋ ์ด sendgrid ๋ฌธ์ ๋ฅผ ์ฐพ์์ต๋๋ค. ์ฃผ์ ๋งค๊ฐ ๋ณ์๊ฐ ์๋ํ์ง ์๋ ๊ฒ ๊ฐ์ต๋๋ค.
@nrator ๊ฐ์ฌํฉ๋๋ค. ์๋ํ์ต๋๋ค. ๋ฐ๋ผ์ <% body %>๋ ํ์ํ์ง ์์ต๋๋ค (์ฃผ์ด์ง ์์ ์ฒ๋ผ ์๋ํ์ง ์๊ธฐ ๋๋ฌธ์).
Btw, ํน์ ๋ฌธ์ ๋ ์๋์ง๋ง์ด ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ํตํด ์ธ๋ถ ์ ๋ณด ๋ชฉ๋ก์ ๋ณด๋ด๋ ๊ฒฝํ์ด๋ ์๊ฐ ์์ต๋๊น? ๋ด ์ฑ์ ๋น๋ํ๋ ๋ฐ ๋์์ด ๋ ๋งํ ๊ฒ์ ์ฐพ๊ณ ์์ต๋๋ค. :)
@ pankaja92 ์ธ๋ถ ์ ๋ณด ๋ชฉ๋ก์ ๋ณด๋ด๋ ๊ฒ์ด ๋ฌด์์ ์๋ฏธํ๋์ง ์ ๋ชจ๋ฅด๊ฒ ์ต๋๋ค. ๋์ ํ ํ๋ฆฟ์ ์๋ก์ด ๊ธฐ๋ฅ์ ๋ํ ์ด sendgrid ๋ธ๋ก๊ทธ ๊ฒ์๋ฌผ์ ์ฝ์ ์ ์์ต๋๋ค. ๊ธฐ๋ณธ์ ์ผ๋ก ํญ๋ชฉ ๋ชฉ๋ก์ ๋ฐ๋ณตํ๊ฑฐ๋ ๊ธฐ๋ณธ ์กฐ๊ฑด์ ์ฌ์ฉํ์ฌ ๋์ ์ฝํ ์ธ ๋ฅผ ์์ฑ ํ ์ ์์ต๋๋ค.
์ค์ ์ฝ๋๋ ์ด ์ ์ฅ์๋ฅผ ์ฐธ์กฐ ํ ์ ์์ต๋๋ค.
๋์์ด ๋์๊ธฐ๋ฅผ ๋ฐ๋๋๋ค.
์๋ ํ์ธ์,์ด ๋ฌธ์ ์๋ ๋ช ์๊ฐ์ ๋ณด๋์ต๋๋ค.
substitutions
๋ฅผ ์ฌ์ฉํ๋ ๋์ ๊ธฐ๋ณธ msg
๊ฐ์ฒด์์ dynamicTemplateData
๋ฅผ ์ฌ์ฉํ์ธ์.
const sgMail = require('@sendgrid/mail')
sgMail.setApiKey(process.env.SENDGRID_API_KEY)
sgMail.setSubstitutionWrappers('{{', '}}')
const msg = {
to: '[email protected]',
from: '[email protected]',
templateId: 'd-27e7d954368c46519eddc806e5cf8156',
dynamicTemplateData: {
name: 'Some One',
city: 'Denver',
},
}
sgMail.send(msg)
์ฐธ์กฐ : https://github.com/sendgrid/sendgrid-nodejs/pull/691
ํด๋น PR์ ๋ฐ๋ฅด๋ฉด templateId
๊ฐ ๋์ ํ
ํ๋ฆฟ ( d-
์ ๋์ฌ)์ด๋ฉด substitutions
๊ฐ ์ ํ ์ ์ก๋์ง ์์ผ๋ฏ๋ก dynamicTemplateData
๊ฐ์ฒด๋ฅผ ์ฌ์ฉํด์ผํฉ๋๋ค.
๋ฌธ์์ ๋์ ํ ํ๋ฆฟ ์ถ๊ฐ ์ฌ์ฉ์ ๊ฐ์ ํ๊ธฐ ์ํด ์ฌ๊ธฐ ์ ๋ฌธ์ ๋ฅผ ๋ง๋ค์์ง ๋ง ๊ทธ๋๊น์ง๋ ์ด๊ฒ์ด ๋์์ด๋๊ธฐ๋ฅผ ๋ฐ๋๋๋ค. ๐
์ด ๋ฌธ์ ๋ฅผ ๋ฐ๋ฅด์ญ์์ค : # 703
'๋์ฒด'๋ฅผ 'dynamic_template_data'๋ก ๋ณ๊ฒฝ
@jseyfert ๋ dynamic_template_data
์ด์ด์ผํ์ง ์์ต๋๊น?
@aroach ๋น์ ์ด ๋ง์ต๋๋ค. ๋ด ๋๊ธ์ ์ ๋ฐ์ดํธํ์ต๋๋ค.
์ฒ์์๋ ๋ด ์ชฝ์์๋ ์๋ํ์ง ์์์ต๋๋ค.
๋ด ๋ฒ์ ์ด ์ฝ๊ฐ ์ค๋๋ ๊ฒ์ผ๋ก ๋ํ๋ฌ์ต๋๋ค (@ sendgrid / mail @ 6.2.1์ ์ฌ์ฉํ์ต๋๋ค).
ํจํค์ง๋ฅผ ์
๋ฐ์ดํธํ๊ณ ์ฝ๋๋ฅผ ๋ณ๊ฒฝํ์ผ๋ฉฐ ์ด์ ์๋ํฉ๋๋ค.
@ sendgrid / [email protected] ์ฌ์ฉ
const result = await this.sgMail.send({
personalizations: [{
to: this._to
}],
dynamicTemplateData: {
test: 'test' <== working (code in template: {{ test }})
},
templateId: this._templateId,
});
์๋ ์ฝ๋๋ ์๋ํ์ง ์์ต๋๋ค.
const result = await this.sgMail.send({
personalizations: [{
to: this._to,
dynamicTemplateData: {
test: 'test' <== NOT working (code in template: {{ test }})
}
}],
templateId: this._templateId,
});
๋ค, dynamic_template_data ์ง์์ ์ํด v6.3.1์ ์ฌ์ฉํด์ผํฉ๋๋ค.
2018 ๋ 12 ์ 11 ์ผ ํ์์ผ ์ค์ 4:15 Roy Milder [email protected] ์ ๋ค์๊ณผ ๊ฐ์ด ์ผ์ต๋๋ค.
์ฒ์์๋ ๋ด ์ชฝ์์๋ ์๋ํ์ง ์์์ต๋๋ค.
๋ด ๋ฒ์ ์ด ์ฝ๊ฐ ์ค๋๋ ๊ฒ์ผ๋ก ๋ํ๋ฌ์ต๋๋ค.
@ sendgrid / mail @ 6.2.1)
ํจํค์ง๋ฅผ ์ ๋ฐ์ดํธํ๊ณ ์ฝ๋๋ฅผ ๋ณ๊ฒฝํ์ผ๋ฉฐ ์ด์ ์๋ํฉ๋๋ค.@ sendgrid / [email protected] ์ฌ์ฉ
const ๊ฒฐ๊ณผ = await this.sgMail.send ({
๊ฐ์ธํ : [{
to : this._to
}],
dynamicTemplateData : {
ํ ์คํธ : 'ํ ์คํธ'<== ์๋ ์ค (ํ ํ๋ฆฟ์ ์ฝ๋ : {{ํ ์คํธ}})
},
templateId : this._templateId,
});โ
๋น์ ์ด ์ธ๊ธ ๋์๊ธฐ ๋๋ฌธ์ ์ด๊ฒ์ ๋ฐ๊ณ ์์ต๋๋ค.
์ด ์ด๋ฉ์ผ์ ์ง์ ๋ต์ฅํ๊ณ GitHub์์ ํ์ธํ์ธ์.
https://github.com/sendgrid/sendgrid-nodejs/issues/676#issuecomment-446166152 ,
๋๋ ์ค๋ ๋ ์์๊ฑฐ
https://github.com/notifications/unsubscribe-auth/ACL-sjFRFP8txUETNWFVLs0chW5yyL1Nks5u35OzgaJpZM4TOB5l
.
์๋
ํ์ธ์, ์์ง ๋ง์ธ์
ํธ๋์ญ์
ํ
ํ๋ฆฟ์ ๋ง๋ค์ง ์๊ณ ๋ ๊ฑฐ์ ํ
ํ๋ฆฟ์ ๋ง๋ค๊ณ ๋ณต์ฌ๋ณธ์ ๋ง๋ญ๋๋ค.
๊ทธ๋ฌ๋ฉด ๋น์ ์ดํ๋ ๋ชจ๋ ๋จ๊ณ๊ฐ ์๋ ํ ๊ฒ์
๋๋ค.
dynamicTemplateData
๋๋ฅผ ์ํด ์๋ํฉ๋๋ค. ์ต์ ๋ฒ์ ์ SendGrid ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ์์ผ๋ฉฐ Firebase (ํจ์)๋ฅผ ํตํด ์ฌ์ฉํ๊ณ ์์ต๋๋ค. ์ด์ ์ฃผ์ ๋ฌธ์ ๋ TypeScript ์ง์ ๋ฐ ๋ฌธ์์ ๋ถ์กฑ์ ๋๋ค.
@roymilder , ์ ๋ง ๊ฐ์ฌํฉ๋๋ค. ๊ทํ์ ๋ต๋ณ์ด ์ ํ๋ฃจ์์ต๋๋ค. ๋์ ํ
ํ๋ฆฟ์ ๋์ฒด๊ฐ ๋งค์ฐ ๋ช
ํํ์ง ์์ต๋๋ค.
๋ช
์ฑ!
์๋ ํ์ธ์ @OleksiiM ,
์ด ์๊ฐ ๋์์ด๋ฉ๋๊น?
@ darren-dev,
๋์ ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค! TypeScript ์ง์ ๋ฐ ๋ฌธ์ ๋ถ์กฑ๊ณผ ๊ด๋ จํ์ฌ Firebase ์ธก์ ์ธ๊ธํ๊ณ ์์ต๋๊น?
@uups ,
๋์ ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค!
๋ง์์ ๋ด์,
Elmer
@thinkingserious , ๊ทธ๋ ์ต๋๋ค. ๊ฐ์ฌํฉ๋๋ค.
@OleksiiM ,
์ด๋๋ฅผ ๋จผ์ ๋ณด์ จ๋์? ๋์ ํ ํ๋ฆฟ์ ์ฌ์ฉํด์ผํ๋ ์ฌ๋๋ค์ด ๋ด๊ฐ ๋จผ์ ๋ณด๋ธ ๋งํฌ๋ก ์ด๋ํ๋๋กํ๋ ๋ฐฉ๋ฒ์ ์์ ๋ณด๋ ค๊ณ ํฉ๋๋ค.
์๋
ํ์ธ์.
์ฌ๊ธฐ์ ์์
๊ทธ๊ฒ์ ๋งํ๋ค :
"ํธ๋์ญ์
ํ
ํ๋ฆฟ ๋ณด๋ด๊ธฐ
๋ค์ ์ธ ๊ฐ์ง ๋ฐฉ๋ฒ ์ค ํ๋๋ฅผ ์ฌ์ฉํ์ฌ ํธ๋์ญ์
ํ
ํ๋ฆฟ์ ๋ณด๋ผ ์ ์์ต๋๋ค.
SMTP ๋ฆด๋ ์ด ์ฌ์ฉ
Web API v3 ๋ฉ์ผ ์ ์ก ์๋ ํฌ์ธํธ์ ํ
ํ๋ฆฟ ๋งค๊ฐ ๋ณ์์ ํ
ํ๋ฆฟ ID ํฌํจ
Web API v2 ๋ฉ์ผ ์ ์ก ์๋ ํฌ์ธํธ์์ x-smtpapi ๋งค๊ฐ ๋ณ์ ์ฌ์ฉ "
๊ทธ๋์ " Web API v3 Mail Send endpoint ์ ํ ํ๋ฆฟ ๋งค๊ฐ ๋ณ์์ ํ ํ๋ฆฟ ID ํฌํจ"์ผ๋ก ์ด๋ํ์ต๋๋ค.
๋ถ๋ถ๋ช
ํ ์ด์ :
๋ง์ง๋ง ํ์ด์ง์๋ template_id๋ฅผ ํ์ํ์ง๋ง "dynamic_template_data"ํ๋์ ๋ํ ๋ด์ฉ์ด์๋ ๊ฐ๋ฅํ "์์ฒญ ๋ณธ๋ฌธ ๋งค๊ฐ ๋ณ์"๋ชฉ๋ก์ด ํ์๋ฉ๋๋ค. ๋๋ "personalizations"+ "substitutions"+ "template_id"๋ก ๊ฐ๋ ค๊ณ ํ์ง๋ง ์๋ํ์ง ์์์ต๋๋ค.
๋ํ ์ ๋ ์๋ก์ด Sendgrid ์ฌ์ฉ์์ด๊ธฐ ๋๋ฌธ์ "์ค๋๋"ํ
ํ๋ฆฟ๊ณผ "์"(๋์ ) ํ
ํ๋ฆฟ๊ณผ ๊ทธ ์ฐจ์ด์ ์ ์์ง ๋ชปํ์ต๋๋ค (์์ sendgrid ๋ฌธ์ ํ์ด์ง๋ ์ด์ ๋ํด ์๋ฌด ๋ง๋ํ์ง ์์ต๋๋ค).
๋ ๋์ ๋ฌธ์๋ฅผ ์์ฒญํ๊ณ ๋ง๋ค์ด ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค. ๋๋ ๋ค๋ฅธ ์ฌ๋๋ค์ด ์ด๋ฌํ ์ ํ์ ๋ฌธ์ ๋ฅผ ํผํ ์ ์๊ธฐ๋ฅผ ๋ฐ๋๋๋ค.
๋ด๊ฐ ์ถ๊ฐ ํ ์ ์๋ค๋ฉด @thinkingserious :
ํ์ฌ ๋ค์ ๋ฌธ์๋ฅผ ์ฌ์ฉํ๊ณ ์์ต๋๋ค : https://sendgrid.com/docs/API_Reference/api_v3.html
์ด๋ฉ์ผ ์ ์ก (https://sendgrid.api-docs.io/v3.0/mail-send)์ ๋ํ ์ง์นจ์ ๊ฐ์ธํ์ dynamic_template_data
๋ฅผ ์ ํ ์ธ๊ธํ์ง ์์ต๋๋ค.
๊ทธ๋์ ๊ทธ๊ฒ๋ ๋ถ๋ถ๋ช ํฉ๋๋ค.
๋์์ด ๋์๊ธฐ๋ฅผ ๋ฐ๋๋๋ค.
ํธ์ ๋ด์ ๊ฐ๊ธฐ
@OleksiiM & @roymilder์๊ฒ ๊ฐ์ฌ๋๋ฆฝ๋๋ค! Twilio SendGrid ์ปค๋ฎค๋ํฐ์ ๋ค์ ๊ธฐ์ฌํด ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค. :)
์๋ ํ์ธ์,์ด ๋ฌธ์ ์๋ ๋ช ์๊ฐ์ ๋ณด๋์ต๋๋ค.
substitutions
๋ฅผ ์ฌ์ฉํ๋ ๋์ ๊ธฐ๋ณธmsg
๊ฐ์ฒด์์dynamicTemplateData
๋ฅผ ์ฌ์ฉํ์ธ์.const sgMail = require('@sendgrid/mail') sgMail.setApiKey(process.env.SENDGRID_API_KEY) sgMail.setSubstitutionWrappers('{{', '}}') const msg = { to: '[email protected]', from: '[email protected]', templateId: 'd-27e7d954368c46519eddc806e5cf8156', dynamicTemplateData: { name: 'Some One', city: 'Denver', }, } sgMail.send(msg)
์ฐธ์กฐ : # 691
ํด๋น PR์ ๋ฐ๋ฅด๋ฉด
templateId
๊ฐ ๋์ ํ ํ๋ฆฟ (d-
์ ๋์ฌ)์ด๋ฉดsubstitutions
๊ฐ ์ ํ ์ ์ก๋์ง ์์ผ๋ฏ๋กdynamicTemplateData
๊ฐ์ฒด๋ฅผ ์ฌ์ฉํด์ผํฉ๋๋ค.๋ฌธ์์ ๋์ ํ ํ๋ฆฟ ์ถ๊ฐ ์ฌ์ฉ์ ๊ฐ์ ํ๊ธฐ ์ํด ์ฌ๊ธฐ ์ ๋ฌธ์ ๋ฅผ ๋ง๋ค์์ง ๋ง ๊ทธ๋๊น์ง๋ ์ด๊ฒ์ด ๋์์ด๋๊ธฐ๋ฅผ ๋ฐ๋๋๋ค. ๐
์ดํ ์ดํ๋ก ํ๋ฅ๋๋ฉฐ ๋๋ ์ด๊ฒ์ ๋ณด์๊ณ ์ด๊ฒ์ ์๋์์ผฐ๋ค.
์๋ ํ์ธ์ @Travotics ,
์์ ๋ฌธ์๋ฅผ ์ฐพ๊ธฐ ์ ์ ์ด๋ค ๋ฌธ์๋ก ์์ ํ์ต๋๊น? ์ด ๊ฒฝํ์ ๊ฐ์ ํ๊ธฐ ์ํด ๋ ธ๋ ฅํ๊ณ ์์ต๋๋ค. ๊ฐ์ฌ!
๋ง์์ ๋ด์,
Elmer
@thinkingserious https://github.com/sendgrid/sendgrid-nodejs/blob/master/use-cases/kitchen-sink.md
dynamicTemplateData
์์ง๋ง substitutionWrappers
๋ฐ substitutions
์์ต๋๋ค.
๋ฌธ์๋ฅผ ์
๋ฐ์ดํธํ๋ ๊ฒ ์ธ์๋ ์ ํ ์ธํฐํ์ด์ค MailData
(https://github.com/sendgrid/sendgrid-nodejs/blob/master/packages/helpers/classes/)๋ฅผ ์
๋ฐ์ดํธํ๋ ๊ฒ๋ ์ข์ต๋๋ค. mail.d.ts # L117). substitutions
์ง์ํ์ง ์๋ @ sendgrid / mail ๋ฆด๋ฆฌ์ค์ ๊ฒฝ์ฐ substititons
๋ฐ substitutionWrappers
ํ๋๊ฐ ์๋ต ๋ V2MailData
๋งค๊ฐ ๋ณ์๋ฅผ ์์ํด์ผํฉ๋๋ค.
์๋ ํ์ธ์, @himanshupnt ์ ์๊ฒฌ์ ์ฝ์ ํ ๋ ๊ฑฐ์ ํ ํ๋ฆฟ์ผ๋ก ํ ์คํธํ์ผ๋ฉฐ ์๋ํ์ต๋๋ค. ๊ฐ์ฌํฉ๋๋ค @himanshupnt .
๋์ค์ Sendgrid ๋ฌธ์ Mail Send with Dynamic Transactional Templates ๋ฅผ ์ฐพ์์ต๋๋ค. ์ ํ ํ๋ฆฟ (๋ ๊ฑฐ์ ํ ํ๋ฆฟ์ด ์๋)์ด ์๋ํฉ๋๋ค. ๋์ผํ HTML ํ ํ๋ฆฟ์ ์ฌ์ฉํ๊ณ ์ฝ๋๊ฐ ๋ค์๊ณผ ๊ฐ์ด ์ ๋ฐ์ดํธ๋์์ต๋๋ค.
const sgMail = require("@sendgrid/mail"); sgMail.setApiKey(process.env.SENDGRID_API_KEY); sgMail.setSubstitutionWrappers("{{", "}}"); // Configure the substitution tag wrappers globally const msg = { from: "[email protected]", templateId: "d-27e7d954368c46519eddc806e5cf8156", personalizations: [ { to: [ { email: "[email protected]" } ], dynamic_template_data: { name: "Someone", city: "Somewhere", subject: "Hello new world" } } ] }; sgMail.send(msg).catch(err => console.error(err.message));
"substitutions"๋ฅผ "dynamic_template_data"๋ก ๋ฐ๊พธ๊ณ ๋ฌธ์์์ ์๊ตฌํ๋๋๋ก "personalizations"์ "to"๋ฅผ ๋ฐฐ์นํ์ต๋๋ค. ๋ํ ์ฃผ์ ๋ฅผ "dynamic_template_data"์ค ํ๋๋ก ์ทจ๊ธํ๊ณ ์๋ํฉ๋๋ค. (ํ ํ๋ฆฟ ์ ๋ชฉ ํ๋์ {{subject}} ์ ๋ ฅ)
๊ฐ์ฌ.
์ ๋ง ๊ฐ์ฌํฉ๋๋ค! ์ด๋ฅผ ์ํด ๋๋ฒ๊น ํ๋ ๋ฐ ์๋นํ ์๊ฐ์ ๋ณด๋์ต๋๋ค. : /
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์๋ ํ์ธ์, @himanshupnt ์ ์๊ฒฌ์ ์ฝ์ ํ ๋ ๊ฑฐ์ ํ ํ๋ฆฟ์ผ๋ก ํ ์คํธํ์ผ๋ฉฐ ์๋ํ์ต๋๋ค. ๊ฐ์ฌํฉ๋๋ค @himanshupnt .
๋์ค์ Sendgrid ๋ฌธ์ Mail Send with Dynamic Transactional Templates ๋ฅผ ์ฐพ์์ต๋๋ค. ์ ํ ํ๋ฆฟ (๋ ๊ฑฐ์ ํ ํ๋ฆฟ์ด ์๋)์ด ์๋ํฉ๋๋ค. ๋์ผํ HTML ํ ํ๋ฆฟ์ ์ฌ์ฉํ๊ณ ์ฝ๋๊ฐ ๋ค์๊ณผ ๊ฐ์ด ์ ๋ฐ์ดํธ๋์์ต๋๋ค.
"substitutions"๋ฅผ "dynamic_template_data"๋ก ๋ฐ๊พธ๊ณ ๋ฌธ์์์ ์๊ตฌํ๋๋๋ก "personalizations"์ "to"๋ฅผ ๋ฐฐ์นํ์ต๋๋ค. ๋ํ ์ฃผ์ ๋ฅผ "dynamic_template_data"์ค ํ๋๋ก ์ทจ๊ธํ๊ณ ์๋ํฉ๋๋ค. (ํ ํ๋ฆฟ ์ ๋ชฉ ํ๋์ {{subject}} ์ ๋ ฅ)
๊ฐ์ฌ.