Created
November 21, 2019 14:38
-
-
Save revolunet/1125fc95b835cf037167b4e55951ef69 to your computer and use it in GitHub Desktop.
Tipimail + fetch
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 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