Crates.io | templateless |
lib.rs | templateless |
version | 0.1.0-alpha.8 |
source | src |
created_at | 2024-01-24 15:50:39.373447 |
updated_at | 2024-03-19 18:54:03.406678 |
description | Ship faster by sending elegant emails using just code |
homepage | https://templateless.com/ |
repository | https://github.com/templateless/templateless-rust |
max_upload_size | |
id | 1112486 |
size | 90,885 |
Ship faster by treating email as code 🚀
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.
Install via Cargo:
cargo add templateless
Or add manually to your Cargo.toml
:
[dependencies]
templateless = "0.1"
You'll need an API key for the example below ⬇️
This is all it takes to send a signup confirmation email:
use templateless::{Content, Email, EmailAddress, Templateless, Result};
#[tokio::main]
async fn main() -> Result<()> {
let content = Content::builder()
.text("Hi, please **confirm your email**:")
.button("Confirm Email", "https://your-company.com/signup/confirm?token=XYZ")
.build()?;
let email = Email::builder()
.to(EmailAddress::new("<YOUR_CUSTOMERS_EMAIL_ADDRESS>"))
.subject("Confirm your signup 👋")
.content(content)
.build()?;
let _result = Templateless::new("<YOUR_API_KEY>")
.send(email)
.await?;
Ok(())
}
There are more Rust 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.
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.
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 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::builder()
.text("## Thank you for signing up")
.text("Please **verify your email** by [clicking here](https://example.com/confirm?token=XYZ)")
.build()?;
Link component adds an anchor tag. This is the same as a text component with the link written in markdown:
Content::builder()
.link("Confirm Email", "https://example.com/confirm?token=XYZ")
.build()?;
Button can also be used as a call to action. Button color is set via your dashboard's app color.
Content::builder()
.button("Confirm Email", "https://example.com/confirm?token=XYZ")
.build()?;
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.
// Simple
Content::builder()
.image("https://placekitten.com/300/200")
.build()?;
// Clickable & with attributes
Content::builder()
.component(
Image::new("https://placekitten.com/300/200")
.url("https://example.com")
.width(200)
.height(100)
.alt("Alt Text")
.build()?
)
.build()?;
Only the src
parameter is required; everything else is optional.
If you have "Image Optimization" turned on:
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.
Images will be converted into formats that are widely supported by email clients. The following image formats will be processed automatically:
Maximum image size is 5MB for free accounts and 20MB for paid accounts.
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.
OTP component is designed for showing temporary passwords and reset codes.
Content::builder()
.text("Here's your **temporary login code**:")
.otp("XY78-2BT0-YFNB-ALW9")
.build()?;
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::builder()
.socials(&[
SocialItem::new(Service::Website, "https://example.com"),
SocialItem::new(Service::Email, "username@example.com"),
SocialItem::new(Service::Phone, "123-456-7890"), // `tel:` link
SocialItem::new(Service::Facebook, "Username"),
SocialItem::new(Service::YouTube, "ChannelID"),
SocialItem::new(Service::Twitter, "Username"),
SocialItem::new(Service::X, "Username"),
SocialItem::new(Service::GitHub, "Username"),
SocialItem::new(Service::Instagram, "Username"),
SocialItem::new(Service::LinkedIn, "Username"),
SocialItem::new(Service::Slack, "Org"),
SocialItem::new(Service::Discord, "Username"),
SocialItem::new(Service::TikTok, "Username"),
SocialItem::new(Service::Snapchat, "Username"),
SocialItem::new(Service::Threads, "Username"),
SocialItem::new(Service::Telegram, "Username"),
SocialItem::new(Service::Mastodon, "@Username@example.com"),
SocialItem::new(Service::Rss, "https://example.com/blog"),
])
.build()?;
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::builder()
.view_in_browser()
.build()?;
Link to your mobile apps via store badges:
Content::builder()
.store_badges(&[
StoreBadgeItem::new(StoreBadge::AppStore, "https://apps.apple.com/us/app/example/id1234567890"),
StoreBadgeItem::new(StoreBadge::GooglePlay, "https://play.google.com/store/apps/details?id=com.example"),
StoreBadgeItem::new(StoreBadge::MicrosoftStore, "https://apps.microsoft.com/detail/example"),
])
.build()?;
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::builder()
.qr_code("https://example.com")
.build()?;
// Email
Content::builder()
.component(QrCode::email("user@example.com"))
.build()?;
// Phone
Content::builder()
.component(QrCode::phone("123-456-7890"))
.build()?;
// SMS / Text message
Content::builder()
.component(QrCode::sms("123-456-7890"))
.build()?;
// Geo coordinates
Content::builder()
.component(QrCode::coordinates(37.773972, -122.431297))
.build()?;
// Crypto address (for now only Bitcoin and Ethereum are supported)
Content::builder()
.component(QrCode::cryptocurrency_address(Cryptocurrency::Bitcoin, "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa"))
.build()?;
// You can also encode any binary data
Content::builder()
.component(QrCode::new(&[1, 2, 3]))
.build()?;
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::builder()
.signature("John Smith")
.build()?;
// Signature with a custom font
Content::builder()
.component(Signature::new("John Smith", Some(SignatureFont::ReenieBeanie)))
.build()?;
These are the available fonts:
SignatureFont::ReenieBeanie
preview →SignatureFont::MeowScript
preview →SignatureFont::Caveat
preview →SignatureFont::Zeyada
preview →SignatureFont::Petemoss
preview →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).
let header = Header::builder() // Header of the email
.text("Smaller text")
.build()?;
let content = Content::builder() // Body of the email
.text("Normal text")
.build()?;
Currently there are 2 themes to choose from: Theme::Unstyled
and Theme::Simple
let content = Content::builder()
.theme(Theme::Simple)
.text("Hello world")
.build()?;
For customer support feel free to email us at github@templateless.com
Have suggestions or want to give feedback? Here's how to reach us: