Skip to main content

Ship faster by sending elegant emails using just code

Project description

Templateless

Ship faster by treating email as code 🚀

WebsiteGet Your API KeyTwitter


PyPI package Github Actions Downloads X (formerly Twitter) Follow

Templateless lets you generate and send transactional emails quickly and easily so you can focus on building your product.

It's perfect for SaaS, web apps, mobile apps, scripts and anywhere you have to send email programmatically.

✨ Features

  • 👋 Anti drag-and-drop by design — emails are a part of your code
  • Components as code — function calls turn into email HTML components
  • 💻 SDK for any language — use your favorite programming language
  • 🔍 Meticulously tested — let us worry about email client compatibility
  • 💌 Use your favorite ESP — Amazon SES, SendGrid, Mailgun + more
  • 💪 Email infrastructure — rate-limiting, retries, scheduling + more
  • Batch sending — send 1 email or 1,000 with one API call

🚀 Getting started

Install the package from PyPI, e. g. with pip:

pip install templateless

Import the Templateless class from the templateless package:

from templateless import Templateless
templateless = Templateless()

🔑 Get Your API Key

You'll need an API key for the example below ⬇️

Get Your API Key

  • 3,000 emails per month
  • All popular email provider integrations
  • Start sending right away

👩‍💻 Quick example

This is all it takes to send a signup confirmation email:

from templateless import Content, Email, EmailAddress, Templateless


def main():
    content = (
        Content()
        .text("Hi, please **confirm your email**:")
        .button("Confirm Email', 'https://your-company.com/signup/confirm?token=XYZ")
        .build()
    )

    email = (
        Email()
        .to(EmailAddress("<YOUR_CUSTOMERS_EMAIL_ADDRESS>"))
        .subject("Confirm your signup 👋")
        .content(content)
        .build()
    )

    templateless = Templateless("<YOUR_API_KEY>")
    templateless.send(email)


if __name__ == "__main__":
    main()

There are more examples in the examples folder ✨

[!NOTE] 🚧 The SDK is not stable yet. This API might change as more features are added. Please watch the repo for the changes in the CHANGELOG.

🏗 Debugging

You can generate test API keys by activating the Test Mode in your dashboard. By using these keys, you'll be able to view your fully rendered emails without actually sending them.

When you use a test API key in your SDK, the following output will appear in your logs when you try to send an email:

Templateless [TEST MODE]: Emailed user@example.com, preview: https://tmpl.sh/ATMxHLX4r9aE

The preview link will display the email, but you must be logged in to Templateless to view it.

🔳 Components

Emails are crafted programmatically by making function calls. There's no dealing with HTML or drag-and-drop builders.

All of the following components can be mixed and matched to create dynamic emails:

Text / Markdown

Text component allow you to insert a paragraph. Each paragraph supports basic markdown:

  • Bold text: **bold text**

  • Italic text: _italic text_

  • Link: [link text](https://example.com)

  • Also a link: <https://example.com>

  • Headers (h1-h6):

    • # Big Header
    • ###### Small Header
  • Unordered list:

    - item one
    - item two
    - item three
    
  • Ordered list:

    1. item one
    1. item two
    1. item three
    
content = (
  Content()
  .text("## Thank you for signing up")
  .text("Please **verify your email** by [clicking here](https://example.com/confirm?token=XYZ)")
  .build()
)
Link

Link component adds an anchor tag. This is the same as a text component with the link written in markdown:

content = (
  Content()
  .link("Confirm Email", "https://example.com/confirm?token=XYZ")
  .build()
)
Button

Button can also be used as a call to action. Button color is set via your dashboard's app color.

content = (
  Content()
  .button("Confirm Email", "https://example.com/confirm?token=XYZ")
  .build()
)
Image

Image component will link to an image within your email. Keep in mind that a lot of email clients will prevent images from being loaded automatically for privacy reasons.

content = (
  Content()
  .image(
    "https://placekitten.com/300/200",  # where the image is hosted
    "https://example.com",              # [optional] link url, if you want it to be clickable
    300,                                # [optional] width
    200,                                # [optional] height
    "Alt text",                         # [optional] alternate text
  )
  .build()
)

Only the src parameter is required; everything else is optional.

If you have "Image Optimization" turned on:

  1. Your images will be cached and distributed by our CDN for faster loading. The cache does not expire. If you'd like to re-cache, simply append a query parameter to the end of your image url.

  2. Images will be converted into formats that are widely supported by email clients. The following image formats will be processed automatically:

    • Jpeg
    • Png
    • Gif
    • WebP
    • Tiff
    • Ico
    • Bmp
    • Svg
  3. Maximum image size is 5MB for free accounts and 20MB for paid accounts.

  4. You can specify width and/or height if you'd like (they are optional). Keep in mind that images will be scaled down to fit within the email theme, if they're too large.

One-Time Password

OTP component is designed for showing temporary passwords and reset codes.

content = (
  Content()
  .text("Here's your **temporary login code**:")
  .otp("XY78-2BT0-YFNB-ALW9")
  .build()
)
Social Icons

You can easily add social icons with links by simply specifying the username. Usually, this component is placed in the footer of the email.

These are all the supported platforms:

content = (
  Content()
  .socials(
    [
      SocialItem(Service.WEBSITE, "https://example.com"),
      SocialItem(Service.EMAIL, "username@example.com"),
      SocialItem(Service.PHONE, "123-456-7890"), # `tel:` link
      SocialItem(Service.FACEBOOK, "Username"),
      SocialItem(Service.YOUTUBE, "ChannelID"),
      SocialItem(Service.TWITTER, "Username"),
      SocialItem(Service.X, "Username"),
      SocialItem(Service.GITHUB, "Username"),
      SocialItem(Service.INSTAGRAM, "Username"),
      SocialItem(Service.LINKEDIN, "Username"),
      SocialItem(Service.SLACK, "Org"),
      SocialItem(Service.DISCORD, "Username"),
      SocialItem(Service.TIKTOK, "Username"),
      SocialItem(Service.SNAPCHAT, "Username"),
      SocialItem(Service.THREADS, "Username"),
      SocialItem(Service.TELEGRAM, "Username"),
      SocialItem(Service.MASTODON, "@Username@example.com"),
      SocialItem(Service.RSS, "https://example.com/blog"),
    ]
  )
  .build()
)
View in Browser

If you'd like your recipients to be able to read the email in a browser, you can add the "view in browser" component that will automatically generate a link. Usually, this is placed in the header or footer of the email.

You can optionally provide the text for the link. If none is provided, default is used: "View in browser"

Anyone who knows the link will be able to see the email.

content = (
  Content()
  .view_in_browser("Read Email in Browser")
  .build()
)
Store Badges

Link to your mobile apps via store badges:

content = (
  Content()
  .store_badges(
    [
      StoreBadgeItem(StoreBadge.APP_STORE, "https://apps.apple.com/us/app/example/id1234567890"),
      StoreBadgeItem(StoreBadge.GOOGLE_PLAY, "https://play.google.com/store/apps/details?id=com.example"),
      StoreBadgeItem(StoreBadge.MICROSOFT_STORE, "https://apps.microsoft.com/detail/example"),
    ]
  )
  .build()
)
QR Code

You can also generate QR codes on the fly. They will be shown as images inside the email.

Here are all the supported data types:

# url
content = (
  Content()
  .qr_code("https://example.com")
  .build()
)

# email
content = (
  Content()
  .component(QrCode.email("user@example.com"))
  .build()
)

# phone
content = (
  Content()
  .component(QrCode.phone("123-456-7890"))
  .build()
)

# sms / text message
content = (
  Content()
  .component(QrCode.sms("123-456-7890"))
  .build()
)

# geo coordinates
content = (
  Content()
  .component(QrCode.coordinates(37.773972, -122.431297))
  .build()
)

# crypto address (for now only Bitcoin and Ethereum are supported)
content = (
  Content()
  .component(QrCode.cryptocurrency_address(Cryptocurrency.BITCOIN, "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa"))
  .build()
)

# you can also encode any binary data
content = (
  Content()
  .component(QrCode.new(bytes([1, 2, 3])))
  .build()
)
Signature

Generated signatures can be added to your emails to give a bit of a personal touch. This will embed an image with your custom text using one of several available fonts:

# signature with a default font
content = (
  Content()
  .signature("John Smith")
  .build()
)

# signature with a custom font
content = (
  Content()
  .signature("John Smith", SignatureFont.REENIE_BEANIE)
  .build()
)

These are the available fonts:

Signature should not exceed 64 characters. Only alphanumeric characters and most common symbols are allowed.


Components can be placed in the header, body and footer of the email. Header and footer styling is usually a bit different from the body (for example the text is smaller).

# header of the email
header = Header().text("Smaller text").build()

# body of the email
content = Content().text("Normal text").build()

Currently there are 2 themes to choose from: Theme.UNSTYLED and Theme.SIMPLE

content = (
  Content()
  .theme(Theme.SIMPLE)
  .text("Hello world")
  .build()
)

🤝 Contributing

  • Contributions are more than welcome
  • Please star this repo for more visibility <3

📫 Get in touch

🍻 License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

templateless-0.1.0a4.tar.gz (27.3 kB view hashes)

Uploaded Source

Built Distribution

templateless-0.1.0a4-py3-none-any.whl (16.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page