Created
January 5, 2021 13:28
-
-
Save aydrian/9f585cc495dfbadebcc0217e5ece4a80 to your computer and use it in GitHub Desktop.
Send an email using Courier with SparkPost that includes an inline image.
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
/* | |
Required environment variables: | |
COURIER_AUTH_TOKEN | |
This will grab an image and convert it to a base64 encoded string. | |
Use `cid:bulbasaur.png` as the image path in the Courier Notification Designer. | |
*/ | |
require("dotenv").config(); | |
const { CourierClient } = require("@trycourier/courier"); | |
const fs = require("fs"); | |
const main = async () => { | |
const courier = CourierClient(); | |
const imageData = fs.readFileSync("bulbasaur.png", { encoding: "base64" }); | |
const { messageId } = await courier.send({ | |
eventId: "BY14E1G7KKMNFAJVYNA1A55WH2F5", | |
recipientId: "AYDRIAN10036", | |
override: { | |
sparkpost: { | |
body: { | |
content: { | |
inline_images: [ | |
{ | |
name: "bulbasaur.png", | |
type: "image/png", | |
data: imageData | |
} | |
] | |
} | |
} | |
} | |
} | |
}); | |
console.log(messageId); | |
}; | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment