Skip to content

Commit 5d4b71f

Browse files
committed
1st commit
0 parents  commit 5d4b71f

File tree

5 files changed

+691
-0
lines changed

5 files changed

+691
-0
lines changed

.gitIgnore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
.env

index.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const dotenv = require('dotenv');
2+
dotenv.config();
3+
4+
const API_KEY = process.env.API_KEY;
5+
const DOMAIN = process.env.DOMAIN;
6+
7+
const mailgun = require('mailgun-js')
8+
({apiKey: API_KEY, domain: DOMAIN});
9+
10+
11+
function getMessage() {
12+
const body = 'This is a test email using Mailgun from Node.js';
13+
return {
14+
to: 'abc@gmail.com',
15+
from: 'mailgun@sandbox01e46ee67ff14ffdb12ac35159a48927.mailgun.org',
16+
subject: 'Test email with Node.js and Mailgun',
17+
text: body,
18+
html: `<strong>${body}</strong>`,
19+
};
20+
}
21+
22+
async function sendEmail() {
23+
try {
24+
await mailgun.messages().send(getMessage(), function (error, body) {
25+
if(error) console.log(error)
26+
else console.log(body);
27+
});
28+
} catch (error) {
29+
console.error('Error sending test email');
30+
console.error(error);
31+
if (error.response) {
32+
console.error(error.response.body)
33+
}
34+
}
35+
}
36+
37+
sendEmail();

0 commit comments

Comments
 (0)