Using Email and Val Town to Draft Blog Posts ============================================ By George Mandis https://george.mand.is/2024/09/using-email-and-val-town-to-draft-blog-posts Sunday, September 29th 2024 ![You have no new email](/media/email-drafts/you-have-no-new-email.jpg) Lately I've been playing around with [Val Town](https://val.town). Their pitch is something like "If AWS Lambdas were fun" and—despite being unable to articulate what that even *means*—I have to chuckle and nod. It's a great product that I've really enjoyed using the past few weeks. Two things in particular have been great about it: - **Free OpenAI access**. It's already pretty cheap to play around with LLMs on most platforms right now, but you can't beat free. - **Email-driven workflows**. I think I find this more compelling than the average person, and the ease with which you can setup scripts that are triggered by inbound emails on Val Town caught my attention. In fact, this post started life as a document I emailed to one of those scripts! ![The email that started this draft](/media/email-drafts/valtown-email-to-draft.png) ## How it works - **We send an email to a special Val Town email address**. Under the hood, I think Val Town is using [SendGrid](https://www.twilio.com/docs/sendgrid/ui/account-and-settings/inbound-parse) to route these emails to my script—specifically their Inbound Parse Webhooks. - **The script takes the plain-text email content** and creates a new draft in my blog's GitHub repository using [Octokit](https://github.com/octokit). ![The email that started this draft](/media/email-drafts/val-town-markdown-converted.png) That's pretty much it? ## Noteworthy - This workflow assumes you're using some sort of static site generator and storing your content in GitHub. There are many to choose from in this space. I'm partial to [11ty](https://www.11ty.dev/). - **Gmail is doing some heavy-lifting for me here** in terms of kindly converting my HTML email to Markdown behind the scenes. There's no guarantee all email providers do this. If yours does not, you may have to investigate an HTML-to-Markdown conversion step. - It uses the GitHub API via [Octokit](https://github.com/octokit) to create the file. You'll need to create a [personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#) and store it an an environmental variable in your Val Town settings. Other services in this space for inbound-email processing: - [Twilio SendGrid](https://www.twilio.com/docs/sendgrid/ui/account-and-settings/inbound-parse) - [Mailgun](https://www.mailgun.com/solutions/use-cases/email-parsing/) - [Amazon SES](https://docs.aws.amazon.com/ses/latest/dg/receiving-email.html) ## What's next I want to try and recreate this workflow with [Cloudflare Email Workers](https://developers.cloudflare.com/email-routing/email-workers/). I finally figured out how to get those working this weekend despite the documentation omitting what felt like a _lot_ of important details. There is a side-project/product I'd like to pursue in this space, and while Val Town is a lot of fun for a quick-and-dirty MVPs (or even [IMPs](/notes/software/imps/)) I'd be nervous trying to run anything resembling areal business on it. Stay tuned! ## The Code If you're on Val Town and want to give it a fave or a fork you can find the script here: - [https://www.val.town/v/georgemandis/convertEmailToBlogDraft](https://www.val.town/v/georgemandis/convertEmailToBlogDraft)