Repository navigation
Expand file tree
/
Copy pathelasticEmail.js
More file actions
69 lines (44 loc) · 1.55 KB
/
Copy pathelasticEmail.js
File metadata and controls
69 lines (44 loc) · 1.55 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const eeClient = require('elasticemail-webapiclient').client;
const express = require("express");
const bodyPaser = require('body-parser');
const app = express();
app.use(bodyPaser());
// Create your Elastic Email Account
// https://elasticemail.com/account/#/create-account
// Or login in your account
// https://elasticemail.com/account/
// after login/signUp you need to get your apiKey from this link
// https://elasticemail.com/account/#/settings/apiconfiguration
app.post("/sendMail", (req, res) => {
let reqbody = req.body;
const options = {
apiKey: 'YOUR API KEY',
apiUri: 'https://api.elasticemail.com/',
apiVersion: 'v2'
}
const EE = new eeClient(options);
// Load account data
EE.Account.Load().then(function (resp) {
console.log(resp);
});
let emailParams = {
"subject": "YOU EMAIL SUBJECT",
"to": "Reciever Email",
"from": "Your registered Email on Elastic email",
"body": "You can give any text or html code to send",
"fromName": "your name/ app name",
"bodyType": 'text or html depends on your body'
};
// you can make it dynamic by using reqBody object by using fetch() method
// in fetch() method, make method : "POST"
// and then send reciever email in body object in fetch() method
// Send email
EE.Email.Send(emailParams)
.catch((err) => {
throw new Error(err);
});
res.send("!!---email Sended---!!")
});
app.listen(process.env.PORT || 5000, () => {
console.log("listnig")
})