Sendgrid-nodejs: ๋Œ€์ฒด๊ฐ€ ์ž‘๋™ํ•˜์ง€ ์•Š์Œ

์— ๋งŒ๋“  2018๋…„ 04์›” 10์ผ  ยท  43์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: sendgrid/sendgrid-nodejs

๋ฌธ์ œ ์š”์•ฝ

๋ณ€๊ฒฝํ•˜์ง€ ์•Š๊ณ  ํŠธ๋žœ์žญ์…˜ ์ด๋ฉ”์ผ์—์„œ ๋Œ€์ฒด๋ฅผ ์‚ฌ์šฉ ํ•˜๋Š”

image

์žฌํ˜„ ๋‹จ๊ณ„

  1. https://github.com/panayi/test-sg/ ๋ณต์ œ
  2. ์˜ˆ์ œ์—์„œ ํ…œํ”Œ๋ฆฟ ๋ณธ๋ฌธ์„ ๋ณต์‚ฌํ•˜๊ณ  SendGrid UI์—์„œ ํŠธ๋žœ์žญ์…˜ ํ…œํ”Œ๋ฆฟ์„ ๋งŒ๋“ญ๋‹ˆ๋‹ค.
  3. test.js ์„ ์ˆ˜์ •ํ•˜์—ฌ API ํ‚ค, ์ด๋ฉ”์ผ ์ฃผ์†Œ ๋ฐ ์œ„์—์„œ ๋งŒ๋“  templateId ์„ ์‚ฝ์ž…ํ•ฉ๋‹ˆ๋‹ค.
  4. node test.js ํ•ฉ๋‹ˆ๋‹ค.

๊ธฐ์ˆ ์  ์„ธ๋ถ€ ์‚ฌํ•ญ:

  • sendgrid-nodejs ๋ฒ„์ „ : @ sendgrid / mail @ 6.2.1
  • Node.js ๋ฒ„์ „ : 8.6.0
unknown or a help wanted question

๊ฐ€์žฅ ์œ ์šฉํ•œ ๋Œ“๊ธ€

์•ˆ๋…•ํ•˜์„ธ์š”, @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}} ์ž…๋ ฅ)

๊ฐ์‚ฌ.

๋ชจ๋“  43 ๋Œ“๊ธ€

์•ˆ๋…•ํ•˜์„ธ์š” @panayi ,

ํ™•์ธํ•ด์•ผ ํ•  ์‚ฌํ•ญ :

  1. ํ…œํ”Œ๋ฆฟ ID๊ฐ€ ์˜ฌ๋ฐ”๋ฅธ์ง€ ํ™•์ธ
  2. UI์—์„œ ํ…œํ”Œ๋ฆฟ์ด ํ™œ์„ฑ

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: ['{{', '}}'] ๋„ ์‚ฌ์šฉํ•ด ๋ณด์•˜์Šต๋‹ˆ๋‹ค.
๋ฉ”์‹œ์ง€ ๋‚ด์—์„œ ๊ทธ๋Ÿฌ๋‚˜ ์šด์ด ์—†์Šต๋‹ˆ๋‹ค.

๊ธฐ์ˆ ์  ์„ธ๋ถ€ ์‚ฌํ•ญ:

  • sendgrid-nodejs ๋ฒ„์ „ : @ sendgrid / [email protected]
  • Node.js ๋ฒ„์ „ : 8.10.0

์ด ๋ฌธ์ œ์— ๋งŽ์€ ์‹œ๊ฐ„์„ ํˆฌ์ž ํ•ด ์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

์•ˆ๋…•ํ•˜์„ธ์š” @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๋Š” ๋‹น์‹ ์ด ๋ณด๋‚ธ ๋Œ€์ฒด๋ฌผ์„ ์–ด๋””์— ๋†“์„ ์ง€ ์•Œ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.

๋ณ€์ˆ˜์— ์ด์ค‘ ๋Œ€๊ด„ํ˜ธ๊ฐ€ ์ •๋ง ํ•„์š”ํ•ฉ๋‹ˆ๊นŒ? ๋‚˜๋Š” ๊ณ„์†ํ•ด์„œ ์‹œ๋„ํ•ด ๋ณผ ๊ฒƒ์ด์ง€๋งŒ ๊ฐ™์€ ์‚ฌ๋žŒ์˜ ๋‹ค๋ฅธ ๊ฒŒ์‹œ๋ฌผ์€ ์ด์ค‘ ๋Œ€๊ด„ํ˜ธ๊ฐ€ ์•„๋‹Œ ๋Œ€์‹œ๋กœ ์ž‘๋™ํ•˜๋Š” ๋Œ€์ฒด๋ฅผ ๋ณด์—ฌ์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.
screenshot 2018-06-26 14 08 12

์•ˆ๋…•ํ•˜์„ธ์š” @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>&nbsp;</div>

<div><span style="font-size:16px;"><strong>Email:</strong>&nbsp;{{email}}</span></div>

<div><strong><span style="font-size:16px;">Password:&nbsp;</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>&nbsp;</div>

<div>&nbsp;</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}} ์ž…๋ ฅ)

๊ฐ์‚ฌ.

์ •๋ง ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค! ์ด๋ฅผ ์œ„ํ•ด ๋””๋ฒ„๊น…ํ•˜๋Š” ๋ฐ ์ƒ๋‹นํ•œ ์‹œ๊ฐ„์„ ๋ณด๋ƒˆ์Šต๋‹ˆ๋‹ค. : /

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰