Hasura SMTP Integration Guide
Guide to integrate Mailazy with your Hasura system
Prerequisites
You need to complete these given prerequisites, you can skip the step if you have already completed.
- Sign up for a Mailazy account.
- Complete Domain Authentication.
- Generate the Mailazy Access Key
Integrate Mailazy with Hasura
Write the webhook
const nodemailer = require("nodemailer");
const transporter = nodemailer.createTransport(
"smtp://" +
process.env.SMTP_LOGIN +
":" +
process.env.SMTP_PASSWORD +
"@" +
process.env.SMTP_HOST
);
const fs = require("fs");
const path = require("path");
const express = require("express");
const bodyParser = require("body-parser");
const app = express();
app.set("port", process.env.PORT || 3000);
app.use("/", express.static(path.join(__dirname, "public")));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(function (req, res, next) {
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader("Cache-Control", "no-cache");
next();
});
app.post("/send-email", function (req, res) {
const name = req.body.event.data.new.name;
// setup e-mail data
const mailOptions = {
from: process.env.SENDER_ADDRESS, // sender address
to: process.env.RECEIVER_ADDRESS, // list of receivers
subject: "A new user has registered", // Subject line
text:
"Hi, This is to notify that a new user has registered under the name of " +
name, // plaintext body
html:
"<p>" +
"Hi, This is to notify that a new user has registered under the name of " +
name +
"</p>", // html body
};
// send mail with defined transport object
transporter.sendMail(mailOptions, function (error, info) {
if (error) {
return console.log(error);
}
console.log("Message sent: " + info.response);
res.json({ success: true });
});
});
app.listen(app.get("port"), function () {
console.log("Server started on: " + app.get("port"));
});
Set the environment variables
After remixing to your own project on Glitch, modify the .env file to enter the
- SMTPLOGIN : mailazyapikey
- SMTPPASSWORD : mailazysecret
- SMTP_HOST : smtp.mailazy.com
- SENDER_ADDRESS : sender email address
- RECEIVER_ADDRESS : receiver email address