-
Notifications
You must be signed in to change notification settings - Fork 1
/
send-mail-from-domain-codefordomain
50 lines (45 loc) · 1.41 KB
/
send-mail-from-domain-codefordomain
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
app.post("/send", (req, res) => {
//console.log(req.body);
const output = `
<p>You have a new contact request</p>
<h3>Contact Details</h3>
<ul>
<li>Name: ${req.body.name}</li>
<li>Company: ${req.body.company}</li>
<li>Email: ${req.body.email}</li>
<li>Phone: ${req.body.phone}</li>
</ul>
<h3>Message</h3>
<p>${req.body.message}</p>
`;
// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
host: "mail.domain.com",
port: 25,
secure: false, // true for 465, false for other ports
auth: {
user: "[email protected]", // your domain email address like [email protected]
pass: "scdfds" // password
},
tls: {
rejectUnauthorized: false
}
});
// setup email data with unicode symbols
let mailOptions = {
from: "[email protected]", // sender address
to: "[email protected]", // list of receivers
subject: "Node Contact Request 2", // Subject line
text: "Hello world?", // plain text body
html: output // html body
};
// send mail with defined transport object
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return console.log(error);
}
console.log("Message sent: %s", info.messageId);
console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
res.render("contact", { msg: "Email has been sent" });
});
});