-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemail.js
34 lines (29 loc) · 1.13 KB
/
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
const nodemailer = require('nodemailer')
async function sendMail(text) {
// create reusable transporter object using the default SMTP transport
const transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 465,
secure: true,
auth: {
type: 'OAuth2',
user: '[email protected]',
clientId: process.env.OAUTH2_CLIENT_ID,
clientSecret: process.env.OAUTH2_CLIENT_SECRET,
refreshToken: process.env.OAUTH2_REFRESH_TOKEN
},
})
// send mail with defined transport object
const info = await transporter.sendMail({
from: '[email protected]', // sender address
to: '[email protected]', // list of receivers
subject: '[ERROR] EPFL CourseNet', // Subject line
text, // plain text 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...
}
module.exports = sendMail