Skip to content
main
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

worker-kit-email

Develop transactional emails quickly using regular SvelteKit routes in your browser, then take it to production by POSTing to that route after deploying on Cloudflare Workers. Uses Cloudflare's free integration with Mailchannels for sending with zero setup.

email

How does it work?

Develop your email templates as regular SvelteKit routes (for example. routes/email/TestEmail).

Put a secret called API_KEY using wrangler:

wrangler secret put API_KEY

Once published on CloudFlare Workers, or when using wrangler dev, POST some JSON to that route to send it as an email:

curl -H "Authorization: your_api_key" \
  -H "Content-Type: application/json" \
  -X POST -d '{ "to": { "name": "John Doe", "email": "john.doe@foobar.com" }, "from": "no-reply@myapp.com", "subject": "Test email from SvelteKit!" }' \
  https://youremailworker.company.workers.dev/email/TestEmail

The route will be rendered on the worker, its CSS will be inlined and the content will be sent to the recipient.

text/plain

striptags is used to strip the tags from the HTML for a text-only version.

Request format

export type EmailAddress = {
  email: string;
  name: string;
};
Variable Type Explanation
subject string E-mail subject
from EmailAddress, string From email address
to EmailAddress[], EmailAddress or string To email address(es)
cc? EmailAddress[], EmailAddress or string CC email address(es)
bcc? EmailAddress[], EmailAddress or string BCC email address(es)
data? { [key: string]: any } Template variables

Template variables

To use template variables that will be replaced from your POST request, use {{{triple_braces}}} in your template.

Then, pass it in your POST data:

{
  "data": {
    "triple_braces": "otters are cool"
  }
}

How do I use it?

Clone this repo.

TODO

  • "click to view this email in your browser" link injection

License

This repository contains a version of striptags modified to compile for CloudFlare Workers.

This repository is licensed under Anti-Capitalist Software License.

About

Develop transactional emails with SvelteKit on CloudFlare Workers

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published