일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- Python
- 유럽여행
- 오라클
- SAP
- 파이썬
- IT
- 영어
- Java
- Programming
- Mac
- 비지니스영어
- SAP ABAP
- 자바스크립트
- docker
- SAP ERP
- JavaScript
- Spring Framework
- 오라클 디비
- db
- 딥러닝
- sap mm
- 도커
- node.js
- oracle
- Oracle DB
- 노드
- nodejs
- 머신러닝
- 자바
- ABAP
- Today
- Total
JIHYUN JEONG
[Node.js]Nodemailer 모듈 (3) – 메일보내기(첨부파일) 본문
이번에는 첨부파일을 보내보도록 하겠습니다.
첨부파일을 보내기 위해서 우선 해당 소스 경로에 ‘attachment_test’ 라는 엑셀파일을 우선 생성합니다. 꼭 해당 소스파일과 같은 경로에 생성해야 합니다.
안에 내용은 간단하게 아래와 같이 작성했습니다. (임의대로 해도 상관없습니다.)
그리고 나서 mailOptions 안에 아래의 attachment 파일에 대한 파일명과 첨부할 파일 경로를 지정해줍니다.
// attachment configuration
attachments: [
{
filename: 'attachment_test.xlsx',
path: 'attachment_test.xlsx',
},
],
};
그리고 소스코드를 실행시키면 아래와 같이 결과 값이 뜰 경우 정상적으로 첨부파일이 발송되었습니다.
Message sent: 250 2.0.0 OK 1513750868 i27sm1485172iod.29 - gsmtp
[ { filename: 'attachment_test.xlsx',
path: 'attachment_test.xlsx' } ]
참고사항: 더 많은 첨부사항 기능과 관련해서는
https://nodemailer.com/message/attachments/ 를 확인하시기 바랍니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | const nodemailer = require('nodemailer');
const transporter = nodemailer.createTransport({ service: 'Gmail', auth: { user: '지메일아이디@gmail.com', pass: '비밀번호', }, });
// setup email data with unicode symbols const mailOptions = {
from: '지메일아이디@gmail.com', // sender address to: '지메일아이디@gmail.com', // list of receivers subject: 'Hello attachment', // Subject line // text: 'Hello world?', // plain text body
// html body html: '<h1>Hello Attachment</h1><a href="http://www.infopub.co.kr">' + '<img src="http://www.infopub.co.kr/pdspool/common/main_top/2016-11-02.jpg"/></p></a>',
// attachment configuration attachments: [ { filename: 'attachment_test.xlsx', path: 'attachment_test.xlsx', }, ], };
// send mail with defined transport object transporter.sendMail(mailOptions, (error, info) => { if (error) { console.log(error); } else { console.log(`Message sent: ${info.response}`); console.log(mailOptions.attachments); } transporter.close(); }); |
In preparing for battle I have always found that plans are useless, but planning is indispensable.
나는 전투를 준비하면서 계획은 무용하나 계획하는 것은 꼭 필요함을 항상 발견해왔다.
'Information Technology > Node.js' 카테고리의 다른 글
카카오 REST API를 활용해 나에게 카카오톡 보내기 (0) | 2018.07.18 |
---|---|
[Node.js]Nodemailer 모듈 (2) – 메일보내기(HTML) (0) | 2018.01.09 |
[Node.js]Nodemailer 모듈 (1) – 메일보내기(TEXT) (0) | 2018.01.08 |
[Node.js] Curl 커맨드 command를 Nodejs/Python/로 작성해보기 (0) | 2018.01.04 |
[Node.js] node-schedule 모듈 (2), job scheduler(배치잡) (0) | 2018.01.03 |