Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example of sending email in Node.js with Candymail.
{
"workflows": [
{
"name": "workflow-one",
"description": "let people know this configuration is working",
"trigger_name": "working-n-testing",
"emails": [
{
"trigger": "time",
"sendDelay": 0,
"subject": "Candymail worked! Workflow-one",
"body": "<h1>It's time to rise up with Candymail</h1><p>Hey {{Firstname}}, look it has HTML support.</p><p><a href='https://saasbase.dev/candymail'>Find out more here!</a></p>",
"from": "yourgmail@gmail.com"
},
{
"trigger": "time",
"sendDelay": 3,
"subject": "Candymail Email on Day Three from workflow-one",
"body": "Sending the next mail at just the right time so your new users don't forget about you: {{Firstname}}. ",
"from": "yourgmail@gmail.com"
}
]
},
{
"name": "workflow-two",
"description": "Different workflow with a different set of timings",
"trigger_name": "working-n-testing",
"emails": [
{
"trigger": "time",
"sendDelay": 1,
"subject": "Workflow Two Email",
"body": "Now is the time for all good men to send email with Candymail",
"from": "yourgmail@gmail.com"
}
]
}
]
}
const candymail = require('candymail')
const automation = require('./candymail-automation.json')
//configure candymail with authorization
candymail.init(automation.workflows, {
mail: {
host: 'smtp.gmail.com',
port: 465,
secure: true,
auth: {
user: 'yourgmail@gmail.com',
pass: 'yourapplicationpassword'
},
tls: {
rejectUnauthorized: true
},
},
hosting: {url: 'testdomain.com'},
db: {reset: true},
debug: {trace: true}
})
.then(() => {
candymail.start();
testUserSignup();
});
const testUserSignup = async() => {
params = [{key: "Firstname", value: "Ted"}, {key: "Lastname", value: "Smith"}]
candymail.runWorkflow('workflow-one', 'myfriend@yahoo.com', params);
}
const testUserUnsubscribe = async() => {
candymail.unsubscribeUser('myfriend@yahoo.com');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment