설치
1. npm install nodemailer nodemailer-smtp-pool --save
1) gmail
2. test.js
var nodemailer = require('nodemailer'); var smtpPool=require('nodemailer-smtp-pool'); var smtpTransport=nodemailer.createTransport(smtpPool( { service:'Gmail', host:'localhost', port:'465', tls:{ rejectUnauthorize:false }, auth:{ user:'지메일 계정주소', pass:'비밀번호' }, maxConnections:5, maxMessages:10 }) ); var mailOpt={ from:'보내는 사람 주소@gmail.com', to:'test@gmail.com', subject:'subject테스트', html:'<h1>테스트임</h1>' } smtpTransport.sendMail(mailOpt, function(err, res) { if( err ) { console.log(err); }else{ console.log('Message send :'+ res); } smtpTransport.close(); })
실행
3. node test.js
2. test.js
const nodemailer = require("nodemailer"); const email = { host: "smtp.mailtrap.io", port: 2525, auth: { user: "07ateew7b9ccc2", pass: "c0b51re33c74af85" } } const send = async (opiton) => { nodemailer.createTransport(email).sendMail(opiton, (error, info) => { if (error) { console.log("error"); console.log(error); } else { console.log("info"); console.log(info); return info.response; } }); } let email_data = { from: 'test@gmail.com', to: 'test@gmail.com', subject: "Hello Node JS", text: "text Hello Node JS" } send(email_data);
실행
3. node test.js
댓글 ( 5)
댓글 남기기