Sendgrid-nodejs: node.js둜 ν…œν”Œλ¦Ώμ—μ„œ λŒ€μ²΄ν•˜λŠ” 방법

에 λ§Œλ“  2016λ…„ 11μ›” 30일  Β·  13μ½”λ©˜νŠΈ  Β·  좜처: sendgrid/sendgrid-nodejs

문제 μš”μ•½

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)
    });

기술적 μ„ΈλΆ€ 사항:

  • sendgrid-nodejs 버전 : master (μ΅œμ‹  컀밋 : [컀밋 번호])
  • Node.js 버전 : 4.1.2
question

κ°€μž₯ μœ μš©ν•œ λŒ“κΈ€

@thinkingseriousκ°€ μ–ΈκΈ‰ ν•œ μœ„μ˜ URL이 μ•½κ°„ λ³€κ²½λœ μ—…λ°μ΄νŠΈ : https://github.com/sendgrid/sendgrid-nodejs/blob/master/use-cases/transactional-templates.md

λͺ¨λ“  13 λŒ“κΈ€

μ•ˆλ…•ν•˜μ„Έμš” @ 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!

μ›λž˜ λŒ“κΈ€μ˜ 링크λ₯Ό μ—…λ°μ΄νŠΈν–ˆμŠ΅λ‹ˆλ‹€.

이 νŽ˜μ΄μ§€κ°€ 도움이 λ˜μ—ˆλ‚˜μš”?
0 / 5 - 0 λ“±κΈ‰