IT,프로그래밍/AWS

sendgrid에서 dynamic template을 쓸때 메일 제목이 안나오는 현상

이번에 AWS lambda를 이용해서 안내 메일을 발송하는 기능을 구현하고있었다.

const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const msg = {
  to: 'test@example.com',
  from: 'test@example.com', // Use the email address or domain you verified above
  subject: 'Sending with Twilio SendGrid is Fun',
  text: 'and easy to do anywhere, even with Node.js',
  html: '<strong>and easy to do anywhere, even with Node.js</strong>',
};
//ES6
sgMail
  .send(msg)
  .then(() => {}, error => {
    console.error(error);

    if (error.response) {
      console.error(error.response.body)
    }
  });
//ES8
(async () => {
  try {
    await sgMail.send(msg);
  } catch (error) {
    console.error(error);

    if (error.response) {
      console.error(error.response.body)
    }
  }
})();

https://github.com/sendgrid/sendgrid-nodejs/tree/master/packages/mail

위와같은 quick start 코드를 했을때는 아무런 문제없이 메일이 잘 발송이 되었다.

 

하지만 이후 다이나믹템플릿(Dynamic templates)을 사용했을때 문제가 발생했다.

 

 

사진에사와 같이 object내부에 subject를 지정해줬음에도 제목없음으로 날아오는 일이 생겼다.

 

이리저리 검색과 테스트를 하던도중 같은 이슈를 가진 github issue를 발견했다

참고링크 → https://github.com/sendgrid/sendgrid-nodejs/issues/843

 

Subject not being set if using Dynamic templates · Issue #843 · sendgrid/sendgrid-nodejs

I was trying to add subject for my email with dynamic templates but it is not working. Is this a known bug already? Can you suggest any workarounds for this issue? template code: <h...< p=""> </h...<>

github.com

깃허브의 내용은 다이나믹 템플릿의 경우 코드가 아닌 gridsend 자체의 다이나믹 템플릿에서 세팅을 해줘야 한다는 뜻이었다.

내용을 따라가보니 실제로 subject를 입력할수 있는 UI가 따로 존재 하였다.

 

 

위와같이 입력을 해주고 다시 발송을 해보니

 

 

메일 제목에 정상적으로 원하는 제목이 입력되었다!