본문 바로가기

STUDY/Node.js

Node.js | nodemailer 이미지 첨부하기 (Embedded Image)

 

mailOptions에 attachments 항목을 추가하고

filename에는 첨부하고자 하는 이미지의 파일명,

path에는 첨부하고자하는 이미지가 담긴 경로(파일 명도 함께 적어주어야 합니다.)

그리고 cid는 html의 img 태그의 src에 적을 내용을 작성합니다.

 

※ 이 방법으로 메일을 전송할 경우 이미지가 첨부파일로 전달됩니다.

 

 const mailOptions = {
      from: 'id@gmail.com',
      to: 'to@email.com',
      subject: '메일 제목',
      html : <img src="cid:logoImg" />,
      attachments: [{
        filename: 'logo.png',
        path: './src/resources/users/images/logo.png',
        cid: 'logoImg'
      }]
    };

 

+)참고

 

Using Embedded Images

Attachments can be used as embedded images in the HTML body. To use this feature, you need to set additional property of the attachment – cid (unique identifier of the file) which is a refere…

community.nodemailer.com