takeout.js

1.3.1 • Public • Published

Takeout.js

Takeout.js is super easy to use. In under 10 lines of code, you can send an email to anyone, anywhere. Ah, the joys of the internet.

Installation 🏗

You can install Takeout.js using either NPM or Yarn.

$ npm install takeout.js
$ yarn add takeout.js

Then, import it like this:

const TakeoutClient = require('takeout.js')
const client = new TakeoutClient()

You can also initialise a new TakeoutClient with 'debug' mode enabled via new TakeoutClient(true). For now, it just prints success messages to the console.

Setup 🛠

First, get your token from the Takeout dashboard. You'll need it in a little bit.

Then, using that token you just got, use it here:

client.login('your token here')

As of right now, your code should look something like this:

const TakeoutClient = require('takeout.js')
const client = new TakeoutClient()
client.login('your token here')

"But I want to actually send an email!" ⇨ we're getting there!

Sending your first email 📤

Define a 'template' similar to this:

const emailTemplate = {
    to: 'test@example.com',
    from: 'Takeout.js', // This will be (e.g) 'Takeout.js via Takeout' for free users
    subject: 'I just sent an email using Takeout!',
    html: "<b>My first email!</b>",
}

or

const emailTemplate = {
    to: 'test@example.com',
    from: 'Takeout.js', // This will be (e.g) 'Takeout.js via Takeout' for free users
    subject: 'I just sent an email using Takeout!',
    text: 'My first email!',
}

and then...

client.send(emailTemplate)

You can also use await for client.send() - where it'll return an email ID. This ID can be used to view your email in the browser.

See? It's super simple. Oh, and you can also import HTML/text directly from a file, using getLocalTemplate() (prev. getHTMLFileContents()). This is demonstrated here:

async function sendEmail() {
    const html = await client.getLocalTemplate('templates/index.html')

    const emailTemplate = {
        to: 'hello@sourfruit.xyz',
        from: 'Takeout.js', // This will be (e.g) 'Takeout.js via Takeout' for free users
        subject: 'Getting HTML from a file',
        html: html,
    }

    await client.send(emailTemplate)
}

sendEmail()

Additional fields

Takeout.js allows you to CC one person (a method to CC more is coming soon). Define this in your template.

const emailTemplate = {
    to: 'test@example.com',
    from: 'Takeout.js', // This will be (e.g) 'Takeout.js via Takeout' for free users
    subject: 'I just sent an email using Takeout!',
    text: 'My first email!',
    cc: 'test@notexample.com'
}

Furthermore, Takeout.js allows you to set a reply-to email. Define this in your template.

const emailTemplate = {
    to: 'test@example.com',
    from: 'Takeout.js', // This will be (e.g) 'Takeout.js via Takeout' for free users
    subject: 'I just sent an email using Takeout!',
    text: 'My first email!',
    replyTo: 'reply@tome.com'
}

Takeout Cloud ☁️

If you're a Takeout+ subscriber, you can upload email templates to Takeout Cloud via the dashboard. You can upload up to 5 templates, each of which can be up to 5 megabytes in size.

You can retrieve your template(s) using the package's built-in method, getCloudTemplate(). It'll only work after client.login(), and it expects the exact file name for your template.

As an example, you'd use this code snippet of code to retrieve a template called SomeRandomCloudTemplate.html

const html = await client.getCloudTemplate('SomeRandomCloudTemplate.html')

In the dashboard, after uploading the template, it'll look similar to this:

If you want to actually do something with the template, consider installing a package like Lodash & their _.template function.

Errors

With the arrival of 1.2.0, came a new method to authenticate with Takeout's API. This removed your token from the request body and moved it to the Authorization header. If you're running an older version Takeout.js, Takeout will throw an error. Upgrade to a version >=1.2.0

Roadmap 🚦

  • Lodash templating built in, allowing you a greater variety of options in a single package (with... well some dependencies).
  • Fixing SMTP email validation.
  • Bug fixes.
  • A lot more.

See complete examples in examples/

Readme

Keywords

none

Package Sidebar

Install

npm i takeout.js

Weekly Downloads

0

Version

1.3.1

License

CC BY 4.0

Unpacked Size

25.2 kB

Total Files

5

Last publish

Collaborators

  • s0urfruit