105 lines
3.7 KiB
JavaScript
105 lines
3.7 KiB
JavaScript
'use strict';
|
|
const nodemailer = require('nodemailer');
|
|
const FROM = '"Qlik" <no-reply@qlik.com>';
|
|
var transporter;
|
|
|
|
if ( process.env.GMAIL_USERNAME && process.env.GMAIL_PASSWORD ) {
|
|
//GMAIL
|
|
transporter = nodemailer.createTransport({
|
|
service: 'gmail',
|
|
port: 587,
|
|
secure: false,
|
|
auth: {
|
|
user: process.env.GMAIL_USERNAME,
|
|
pass: process.env.GMAIL_PASSWORD
|
|
}
|
|
});
|
|
} else {
|
|
//QLIK
|
|
transporter = nodemailer.createTransport({
|
|
host: 'smtp.qliktech.com',
|
|
port: 587,
|
|
secure: false, // true for 465, false for other ports
|
|
});
|
|
}
|
|
|
|
|
|
function getHtmlNewProvision(provision, scenario) {
|
|
var htmlint;
|
|
if ( provision && provision.outputs ) {
|
|
htmlint = `<div style="color:#404040;font-size:18px;padding: 10px 0px;">Connection resources</div>`;
|
|
} else {
|
|
htmlint = "";
|
|
}
|
|
for (let key in provision.outputs) {
|
|
htmlint += `<div>
|
|
<span style="color:#404040">${key}</span>
|
|
<pre style="color:#404040;">${provision.outputs[key]}</pre>
|
|
</div>`;
|
|
}
|
|
|
|
return`<div style="width:600px;color:black!important;font-family:'Source Sans Pro',sans-serif;padding:50px">
|
|
<div style="background-color:white;height:100%;padding:10px">
|
|
<p style="text-align:left;margin-bottom:30px;margin-left:0px">
|
|
<img src="https://www.qlik.com/us/-/media/images/qlik/global/qlik-logo-2x.png" width="150" height="32" alt="Qlik" style="border:0;height:auto;line-height:100%;outline:none;text-decoration:none" class="CToWUd">
|
|
</p>
|
|
<div style="color:#404040;font-size:34px;text-align:center;margin:20px">
|
|
<p style="margin:0px">QMI Cloud</p>
|
|
</div>
|
|
<div style="color:#404040;font-size:20px;margin:20px 0px">
|
|
<p style="margin:0px">${scenario.description} successfully provisioned!</p>
|
|
</div>
|
|
|
|
<div style="color:#404040;font-size:18px;margin:20px 0px">
|
|
<p style="margin:0px">Scenario information:</p>
|
|
</div>
|
|
<div>
|
|
<span style="color:#404040">Scenario: </span> ${scenario.description}
|
|
</div>
|
|
<div>
|
|
<span style="color:#404040">ProvisionID: </span> ${provision._id}
|
|
</div>
|
|
<div>
|
|
<span style="color:#404040">Instance Type: </span> ${provision.vmType}
|
|
</div>
|
|
|
|
${htmlint}
|
|
|
|
</div>
|
|
</div>`;
|
|
}
|
|
|
|
// async..await is not allowed in global scope, must use a wrapper
|
|
async function send( provision, user, scenario ) {
|
|
/*let testAccount = await nodemailer.createTestAccount();
|
|
|
|
// create reusable transporter object using the default SMTP transport
|
|
let transporter = nodemailer.createTransport({
|
|
host: "smtp.ethereal.email",
|
|
port: 587,
|
|
secure: false, // true for 465, false for other ports
|
|
auth: {
|
|
user: testAccount.user, // generated ethereal user
|
|
pass: testAccount.pass // generated ethereal password
|
|
}
|
|
});*/
|
|
const htmlText = getHtmlNewProvision(provision, scenario);
|
|
|
|
// create reusable transporter object using the default SMTP transport
|
|
|
|
// send mail with defined transport object
|
|
let info = await transporter.sendMail({
|
|
from: FROM, // sender address
|
|
to: user.upn, // list of receivers
|
|
subject: 'QMI Cloud - Provision finished successfully', // Subject line
|
|
text: 'QMI Cloud - Provision finished successfully', // plain text body
|
|
html: htmlText // html body
|
|
});
|
|
|
|
console.log('Provision Email ('+info.messageId+') sent to: ' + user.upn);
|
|
|
|
//console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
|
|
}
|
|
|
|
module.exports.send = send;
|