-
Notifications
You must be signed in to change notification settings - Fork 0
/
send_email.js
41 lines (34 loc) · 1.17 KB
/
send_email.js
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');
nodemailer.createTestAccount((err, account) => {
if (err) {
console.error('Failed to create a testing account. ' + err.message);
return process.exit(1);
}
console.log('Credentials obtained, sending message...');
let transporter = nodemailer.createTransport({
host: account.smtp.host,
port: account.smtp.port,
secure: account.smtp.secure,
disableFileAccess: true,
disableUrlAccess: true,
auth: {
user: account.user,
pass: account.pass
}
});
let message = {
from: 'Sender Name <[email protected]>',
to: 'Recipient <[email protected]>',
subject: 'Nodemailer is unicode friendly ✔',
text: 'Hello to myself!',
html: '<p><b>Hello</b> to myself!</p>'
};
transporter.sendMail(message, (err, info) => {
if (err) {
console.log('Error occurred. ' + err.message);
return process.exit(1);
}
console.log(`Message sent: ${info.messageId}`);
console.log(`Preview URL: %s ${nodemailer.getTestMessageUrl(info)}`);
});
});