Loophook
Search…
Schedule an Email for Later
This is a guide on how you can schedule an email using Loophook.

Set up the server

The server setup here is simple. A POST endpoint is defined which is listens to request
The sendEmail function sends a test email using nodemailer.
server.js
1
const express = require("express");
2
const nodemailer = require("nodemailer");
3
​
4
async function sendEmail() {
5
// Generate test SMTP service account from ethereal.email
6
let testAccount = await nodemailer.createTestAccount();
7
let transporter = nodemailer.createTransport({
8
host: "smtp.ethereal.email",
9
port: 587,
10
secure: false, // true for 465, false for other ports
11
auth: {
12
user: testAccount.user, // generated ethereal user
13
pass: testAccount.pass, // generated ethereal password
14
},
15
});
16
​
17
let info = await transporter.sendMail({
18
from: '"Fred Foo πŸ‘»" <[email protected]>', // sender address
19
to: "[email protected], [email protected]", // list of receivers
20
subject: "Hello βœ”", // Subject line
21
text: "Hello world?", // plain text body
22
html: "<b>Hello world?</b>", // html body
23
});
24
​
25
console.log("Message sent: %s", info.messageId);
26
​
27
// Preview URL: https://ethereal.email/message
28
console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
29
​
30
}
31
​
32
const app = express();
33
​
34
app.use(express.static("public"));
35
app.use(express.json());
36
​
37
app.post("/send-email", async (req, res) => {
38
await sendEmail();
39
return res.sendStatus(200);
40
});
41
​
42
app.listen(5000, () => console.log("Server listening on port 5000"));
Copied!

Download and install ngrok

To allow sending request to the server on localhost, a tunneling service like ngrok is required. You can download it from https://ngrok.com/download. Once done, simply follow the steps and start a tunnel on port 5000.

Creating a Task

Go to the Loophook dashboard and add your ngrok endpoint.
​
Create a request to /send-email.
Define a schedule, here it's a cron that runs every minute.
Run the task.
Running the task should print something similar to the following in the console.