-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
37 lines (31 loc) · 931 Bytes
/
index.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
const dotenv = require('dotenv');
dotenv.config();
const API_KEY = process.env.API_KEY;
const DOMAIN = process.env.DOMAIN;
const mailgun = require('mailgun-js')
({apiKey: API_KEY, domain: DOMAIN});
function getMessage() {
const body = 'This is a test email using Mailgun from Node.js';
return {
to: 'abc@gmail.com',
from: 'mailgun@sandbox01e46ee67ff14ffdb12ac35159a48927.mailgun.org',
subject: 'Test email with Node.js and Mailgun',
text: body,
html: `<strong>${body}</strong>`,
};
}
async function sendEmail() {
try {
await mailgun.messages().send(getMessage(), function (error, body) {
if(error) console.log(error)
else console.log(body);
});
} catch (error) {
console.error('Error sending test email');
console.error(error);
if (error.response) {
console.error(error.response.body)
}
}
}
sendEmail();