Takeout-bysourfruit / takeout.py

A Takeout client for Python
https://pypi.org/project/takeout.py/
Creative Commons Attribution 4.0 International
1 stars 0 forks source link
email python

Takeout.py

Takeout.py 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 pip

$ pip install takeout.py

Then, import it like this:

from takeout import TakeoutClient

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:

TakeoutClient.login('your token here')

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

from takeout import TakeoutClient
TakeoutClient.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:

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

or

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

and then...

TakeoutClient.send(**emailTemplate)

Note! Unlike Takeout.js, Takeout.py does not yet return an email ID.

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:

file = TakeoutClient.getLocalTemplate('test.html')

emailTemplate = {
    'to': 'test@example.com',
    'from': 'Takeout.py', # This will be (e.g) 'Takeout.py via Takeout' for free users
    'subject': 'I just sent an email using Takeout!',
    'html': file,
}

TakeoutClient.send(**emailTemplate)

Additional fields

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

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

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

emailTemplate = {
    'to': 'test@example.com',
    'from': 'Takeout.py', # This will be (e.g) 'Takeout.py 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 TakeoutClient.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

 template =  TakeoutClient.getCloudTemplate('SomeRandomCloudTemplate.html')

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

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.py, Takeout will throw an error. Upgrade to a version >=1.2.0.

With the arrival of 1.3.0, getHTMLFileContents() was renamed to getLocalTemplate(). If you're running an older version Takeout.py, Takeout will throw an error. Upgrade to a version >=1.3.0.

Roadmap 🚦

See complete examples in examples/