Skip to content

Instantly share code, notes, and snippets.

@revolunet
Created November 21, 2019 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save revolunet/1125fc95b835cf037167b4e55951ef69 to your computer and use it in GitHub Desktop.
Save revolunet/1125fc95b835cf037167b4e55951ef69 to your computer and use it in GitHub Desktop.
Tipimail + fetch
const fetch = require("node-fetch");
const message = {
"X-TM-TAGS": ["welcome", "website1"],
to: [
{
address: "user@example.com",
personalName: "juju"
}
],
msg: {
from: {
personalName: "Raymond",
address: "raymond@example.com"
},
replyTo: {
personalName: "Raymond",
address: "raymond@example.com"
},
subject: "Hello {{name}}",
text: "Whats up {{name}}",
html: "<p>Whats up {{name}}</p>",
// "images": [
// {
// "contentType": "image/png",
// "filename": "IMAGECID",
// "content": "azerty"
// }
// ],
attachments: [
{
contentType: "text/plain",
filename: "myfile.txt",
content: "azerty"
}
]
},
headers: {
"X-TM-META": {
"some-meta": 123
},
"X-TM-SUB": [
{
email: "user@example.com",
values: {
name: "Bobby",
uniqueId: 132456798
}
}
]
}
};
const TIPIMAIL_URL = "https://api.tipimail.com/v1/messages/send";
const TIPIMAIL_USER = "xxx";
const TIPIMAIL_KEY = "yyy";
fetch(TIPIMAIL_URL, {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-Tipimail-ApiUser": TIPIMAIL_USER,
"X-Tipimail-ApiKey": TIPIMAIL_KEY
},
body: JSON.stringify(message)
})
.then(r => r.json())
.then(result => {
console.log("result", JSON.stringify(result, null, 2));
})
.catch(console.error);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment