82 lines
2.6 KiB
JavaScript
82 lines
2.6 KiB
JavaScript
import nodemailer from "nodemailer";
|
|
|
|
export default function handler(req, res) {
|
|
const { email, subject, emailcontenttitle, emailcontent } = req.body;
|
|
console.log(email);
|
|
//console.log(process.env);
|
|
|
|
const client = nodemailer.createTransport({
|
|
auth: {
|
|
user: process.env.EMAIL_SERVER_USER,
|
|
pass: process.env.EMAIL_SERVER_PASSWORD,
|
|
},
|
|
host: process.env.EMAIL_SERVER_HOST,
|
|
port: process.env.EMAIL_SERVER_PORT,
|
|
secure: true,
|
|
});
|
|
|
|
//console.log(client);
|
|
|
|
// Some simple styling options
|
|
const backgroundColor = "#ffffff";
|
|
const textColor = "#444444";
|
|
const mainBackgroundColor = "#ffffff";
|
|
const buttonBackgroundColor = "#aa1111";
|
|
const buttonBorderColor = "#aa1111";
|
|
const buttonTextColor = "#ffffff";
|
|
const headerBackgroundColor = "#000000";
|
|
const url = process.env.API_ROOT;
|
|
|
|
let emailBodyContent = ` <body style="background: ${backgroundColor};">
|
|
<table width="100%" border="0" cellspacing="0" cellpadding="0">
|
|
<tr>
|
|
<td align="center" style="padding: 10px 0px 20px 0px; font-size: 22px; font-family: Helvetica, Arial, sans-serif; color: #fff;background-color: ${headerBackgroundColor};border-bottom: 10px solid #ffd530;>
|
|
|
|
<strong>PEDW - Planning Casework</strong>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<table width="100%" border="0" cellspacing="20" cellpadding="0" style="background: ${mainBackgroundColor}; max-width: 600px; margin: auto; border-radius: 10px;">
|
|
<tr>
|
|
<td align="left" style="padding: 10px 0px 0px 0px; font-size: 18px; font-family: Helvetica, Arial, sans-serif; color: ${textColor};">
|
|
${emailcontenttitle}
|
|
</td>
|
|
<img src ="${url}/assets/images/planning-casework-en.svg"/>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" style="padding: 10px 0px 0px 0px; font-size: 18px; font-family: Helvetica, Arial, sans-serif; color: ${textColor};">
|
|
${emailcontent}
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="center" style="padding: 20px 0;">
|
|
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="center" style="padding: 0px 0px 10px 0px; font-size: 16px; line-height: 22px; font-family: Helvetica, Arial, sans-serif; color: ${textColor};">
|
|
If you did not request this email you can safely ignore it.
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</body>`;
|
|
|
|
const mailData = {
|
|
from: "no-reply@rdbdigital.com",
|
|
to: email,
|
|
subject: subject,
|
|
text: emailBodyContent,
|
|
html: emailBodyContent,
|
|
};
|
|
|
|
client.sendMail(mailData, (err, data) => {
|
|
if (err) {
|
|
console.log(err);
|
|
res.status(400);
|
|
} else {
|
|
console.log("mail sent");
|
|
res.status(200).json(data);
|
|
}
|
|
});
|
|
}
|