
423
부록
D
이메일 전송
D.1.1
메일 전송
수신자 한 명에게 메일을 보낼 때는 다음과 같이 보냅니다.
/* 초기화 */
const msg = {
to: ‘joecustomer@gmail.com’,
from: ‘”Meadowlark Travel” <info@meadowlarktravel.com>’,
// 발신자 인증을 잊지 마세요.
subject: ‘Your Meadowlark Travel Tour’,
text: ‘Thank you for booking your trip with Meadowlark Travel.’,
};
async function send (msg) {
try {
const result = await transport.sendMail(msg)
console.log(‘mail sent successfully: ‘, result)
// API 응답은 상당히 장황한 편이므로 필요한 것만 보세요.
} catch(err) {
console.log(‘could not send mail: ‘ + err.message)
}
}
send(msg)
저자가 언급하지 않았는데
async
/
await
는 전역 스코프에서 허용되지 않으므로 위 예제와 같
이 래퍼를 만들어 사용해야 합니다. 메일에 해당하는 객체를 함수 안에 쓰는 것보다는 위 예제
처럼 분리하는 편이 ...