Sendgrid-nodejs: νŠΈλžœμž­μ…˜ 이메일을 보내렀고 ν•  λ•Œ 예기치 μ•Šμ€ 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€.

에 λ§Œλ“  2017λ…„ 08μ›” 31일  Β·  23μ½”λ©˜νŠΈ  Β·  좜처: sendgrid/sendgrid-nodejs

문제 μš”μ•½

λ‹€μŒ νŽ˜μ΄λ‘œλ“œμ—μ„œ '잘λͺ»λœ μš”μ²­'였λ₯˜κ°€ λ°œμƒν•©λ‹ˆλ‹€.

의뒰

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μ—μ„œ μ˜¬λ°”λ₯΄κ²Œ κ΅¬μ„±λ˜μ—ˆλŠ”μ§€ ν™•μΈν•˜κΈ° μœ„ν•΄ ν…œν”Œλ¦Ώ ν™”λ©΄μ˜ 슀크린 샷을 온 μ „μ„± κ²€μ‚¬λ‘œ μ²¨λΆ€ν–ˆμŠ΅λ‹ˆλ‹€.

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

  • sendgrid-nodejs 버전 : master (μ΅œμ‹  컀밋 : [컀밋 번호])
  • Node.js 버전 : 6.10.3
  • AWS Lambda ν•¨μˆ˜μ—μ„œ μ‹€ν–‰

screen shot 2017-08-30 at 6 43 57 pm

help wanted bug

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

도와 μ£Όμ…”μ„œ κ°μ‚¬ν•©λ‹ˆλ‹€. λ‚˜λŠ” 말 κ·ΈλŒ€λ‘œ 정신을 μžƒκ³  μžˆμ—ˆλ‹€. λ‚˜λŠ” λ§ˆμΉ¨λ‚΄ μ–΄μ ―λ°€ 늦게 ν•΄κ²° 방법을 μ•Œμ•„ λƒˆκ³  더 λ§Žμ€ 정보λ₯Όλ³΄κ³ ν•˜κΈ° μœ„ν•΄ 여기에 μ™”μ§€λ§Œ λͺ¨λ‘κ°€ 이미 그것에 λŒ€ν•΄ μ•Œκ³ μžˆλŠ” 것 κ°™μŠ΅λ‹ˆλ‹€ :-)

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

@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 λ¬Έμ„œλ₯Ό 읽고 ν•„λ“œκ°€ ν•„μˆ˜λΌκ³  μƒκ°ν–ˆμŠ΅λ‹ˆλ‹€. λ‚΄κ°€ λ†“μΉœ 잘 μˆ¨κ²¨μ§„ 주석 (λ†€λΌμš΄ μŠ€νƒ€μΌμž…λ‹ˆλ‹€!) 만 μžˆμŠ΅λ‹ˆλ‹€.

image

λ‚˜λŠ” 이것을 ν•΄κ²°ν•˜κΈ° μœ„ν•΄ 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" }] 쀄을 μ‚¬μš©ν•˜μ—¬ μ§€κΈˆ μž‘λ™ν•˜λŠ”μ§€ ν™•μΈν•©λ‹ˆλ‹€ πŸ‘

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