forked from maildev/maildev
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
example-sendmail.js
34 lines (27 loc) · 1.13 KB
/
example-sendmail.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
'use strict'
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
const nodemailer = require('nodemailer')
async function main () {
const { user, pass } = await nodemailer.createTestAccount()
const transporter = nodemailer.createTransport({
host: '0.0.0.0',
port: 8025,
auth: { type: 'login', user, pass }
})
// send mail with defined transport object
const info = await transporter.sendMail({
from: '\'Fred Foo 👻\' <[email protected]>', // sender address
to: '[email protected], [email protected]', // list of receivers
cc: '[email protected], [email protected]', // optional
bcc: '[email protected], [email protected]', // optional
subject: 'Hello ✔', // Subject line
text: 'Hello world?', // plain text body
html: '<b>Hello world?</b>' // html body
})
console.log('Message sent: %s', info.messageId)
// Message sent: <[email protected]>
// Preview only available when sending through an Ethereal account
console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info))
// Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
}
main().catch(console.error)