-
-
Save LooseTerrifyingSpaceMonkey/122e02e77ba3f2f8a245a6641732bb99 to your computer and use it in GitHub Desktop.
Example of sending email in Node.js with Candymail.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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" | |
} | |
] | |
} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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