templateless 0.1.0-alpha.8

Ship faster by sending elegant emails using just code
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
<h1 align="center">
  <a href="https://templateless.com/">
    <img src="templateless.webp" alt="Templateless" width="450px">
  </a>
  <br />
</h1>

<p align="center">
  <b>Ship faster by treating email as code 🚀</b> <br />
</p>

<h4 align="center">
  <a href="https://templateless.com/">Website</a> &bull;
  <a href="https://app.templateless.com/">Get Your API Key</a> &bull;
  <a href="https://twitter.com/templateless">Twitter</a>
</h4>

---

[![Latest version](https://img.shields.io/crates/v/templateless.svg)](https://crates.io/crates/templateless)
[![Github Actions](https://img.shields.io/github/actions/workflow/status/templateless/templateless-rust/tests.yml)](https://github.com/templateless/templateless-rust/actions)
[![Docs](https://docs.rs/templateless/badge.svg)](https://docs.rs/templateless/latest/templateless/)
[![Crates.io Total Downloads](https://img.shields.io/crates/d/templateless)](https://crates.io/crates/templateless)
[![X (formerly Twitter) Follow](https://img.shields.io/twitter/follow/Templateless)](https://twitter.com/templateless)

[Templateless](https://templateless.com) 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]https://github.com/orgs/templateless/repositories
- 🔍 **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 via Cargo:

```bash
cargo add templateless
```

Or add manually to your `Cargo.toml`:

```toml
[dependencies]
templateless = "0.1"
```

## 🔑 Get Your API Key

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

[![Get Your API Key](https://img.shields.io/badge/Get_Your_API_Key-free-blue?style=for-the-badge)](https://app.templateless.com/)

- 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:

```rust
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](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]CHANGELOG.md.

## 🏗 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:

```log
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:

<details>
  <summary>Text / Markdown</summary>

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:

  ```md
  - item one
  - item two
  - item three
  ```

- Ordered list:

  ```md
  1. item one
  1. item two
  1. item three
  ```

```rust
Content::builder()
  .text("## Thank you for signing up")
  .text("Please **verify your email** by [clicking here](https://example.com/confirm?token=XYZ)")
  .build()?;
```

</details>
<details><summary>Link</summary>

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

```rust
Content::builder()
  .link("Confirm Email", "https://example.com/confirm?token=XYZ")
  .build()?;
```

</details>
<details><summary>Button</summary>

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

```rust
Content::builder()
  .button("Confirm Email", "https://example.com/confirm?token=XYZ")
  .build()?;
```

</details>
<details><summary>Image</summary>

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.

```rust
// 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:**

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.
1. 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

1. Maximum image size is 5MB for free accounts and 20MB for paid accounts.
1. 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.

</details>
<details><summary>One-Time Password</summary>

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

```rust
Content::builder()
  .text("Here's your **temporary login code**:")
  .otp("XY78-2BT0-YFNB-ALW9")
  .build()?;
```

</details>
<details><summary>Social Icons</summary>

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:

```rust
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()?;
```

</details>
<details><summary>View in Browser</summary>

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.**

```rust
Content::builder()
  .view_in_browser()
  .build()?;
```

</details>
<details><summary>Store Badges</summary>

Link to your mobile apps via store badges:

```rust
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()?;
```

</details>
<details><summary>QR Code</summary>

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:

```rust
// 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()?;
```

</details>
<details><summary>Signature</summary>

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:

```rust
// 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 →]https://fonts.google.com/specimen/Reenie+Beanie
- `SignatureFont::MeowScript` [preview →]https://fonts.google.com/specimen/Meow+Script
- `SignatureFont::Caveat` [preview →]https://fonts.google.com/specimen/Caveat
- `SignatureFont::Zeyada` [preview →]https://fonts.google.com/specimen/Zeyada
- `SignatureFont::Petemoss` [preview →]https://fonts.google.com/specimen/Petemoss

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

</details>

---

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).

```rust
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`

```rust
let content = Content::builder()
  .theme(Theme::Simple)
  .text("Hello world")
  .build()?;
```

## 🤝 Contributing

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

## 📫 Get in touch

- For customer support feel free to email us at [github@templateless.com]mailto:github@templateless.com

- Have suggestions or want to give feedback? Here's how to reach us:

    - For feature requests, please [start a discussion]https://github.com/templateless/templateless-rust/discussions
    - Found a bug? [Open an issue!]https://github.com/templateless/templateless-rust/issues
    - Say hi [@Templateless]https://twitter.com/templateless 👋

## 🍻 License

[MIT](LICENSE)