RSS to newsletter
Having recently discovered I could use Infomaniak’s newsletter service, as a subscriber of the hosting offer, I’ve first tested it by creating a subscription to my books release. But following that, I wanted to steal inspire myself with Kev Quirk’s idea of using a RSS feed to send new blog articles by email.
Kev’s blog uses Buttondown, which allows by design to use a RSS feed to send e-mail to subscribers. But it’s a pay service and since I’ve already one included in my hosting provider offer, I’ve preferred to check on this first.
The idea
When I post a new article on my blog, I want people who subscribed to the e-mail notification (because it’s not a newsletter actually, just a RSS to e-mail content) receiving the new article by mail. Since my only automation system would be GitHub Actions, I’ve design something using it but keeping in mind that I should avoid any vendor lock-in patterns.
Here is the proposed workflow.
With this workflow, a scheduled job would check every hours (because I don’t post new articles that often, it would be enough to keep a smooth delay) the RSS feed. The automation repository is basically containing a GitHub workflow and files containing the last RSS entry content. If the latest entry differs, it will commit it in the repository to keep a track.
About Infomaniak’s newsletter service
Infomaniak’s newsletter service is a part of their marketing tools. And it’s a product clearly oriented for marketing usage, not fully automated and basic like I want. But it still have some API for an automated usage, so you have to put your hands in the dirt.
To use it, you need first to setup a Mailing List in the product. It will be you recipient list.
Then, you can create a form in which your readers would be able to subscribe.
Following that, you create a campaign, which is basically the mail to send.
As you can see, they provide fancy templates.
But that’s terribly manual actually, I don’t want to waste my time with click-click GUI. So let’s construct something automated.
The only required part on this step would be the Mailing list and the Subscription Form. I will not use the Campaign creation tool.
Developping some scripts
I’ve made four scripts for this workflow. They’re all available on GitHub. It’s basically just API wrappers from Infomaniak’s definition. The RSS script was made a couple of times ago when I wanted to publish the latest RSS entries on my Homepage. It’s a modified version. They’re all Python scripts and can be used independently from GitHub.
Since they’re related to a specific newsletter provider, I can’t assume they would be reusable for another one. Don’t forget to create your API key on the developer’s portal.
rss-to-html
This one’s purpose is to fetch the latest entry of my RSS feed, generate the e-mail content using a Jinja2 template, and write into the result into three files :
- The article’s title
- The article’s URL
- The article’s Content
Actually, the URL is useless because at first I wanted to use it as a unique identifier to ensure the article is new. But the idea got thrown away.
create-campaign
As said by its name, this script will create the campaign in Infomaniak’s newsletter service. It will take in input the various required informations :
- The e-mail content
- The title
- The sender’s address and name
- The mailing list identifier
Once executed, the script will return the campaign’s ID.
test-campaign
A more simple one, this script use the test API to send a test e-mail to a specific recipient. It takes the Campaign ID and the destination e-mail as an input and returns the API result.
send-campaign
Once you’ve validated your e-mail, this one will trigger the execution. By design, Infomaniak will schedule it and send them a few minutes later.
Actually, I didn’t used this script in the automated setup because the initial idea get impossible to do with GitHub because of free accounts restrictions.
Orchestrate this with GitHub
Aside from the scripts repository, I’ve created a dedicated one in private for the orchestration. And because of that, I couldn’t use the workflow approbation feature, limited to paid subscription from private usage. This was the idea behind send-campaign : once the campaign is created, the sending will be put in hold waiting for me to validate it.
Anyway.
As the scripts are proposed as GitHub Actions, these specific parts are effectively vendor locked because they use GitHub’s variables. But they’re just basic Dockerfile and entrypoint, nothing essential neither difficult to change.
The automation repository contains an Actions workflow which do the following steps :
- Check job
- Checkout the repository
- Executes the RSS to HTML script
- Commit the result on the repository using a
git diff
to verify actual changes - Registers a flag for the next job
- Prepare Job
- If the flag is positive, the job is triggered
- Checkout the repository content
- Feed some variables with the files contents
- Executes the Create campaign script
- Executes the Test campaign script (sending the e-mail to me)
Test it
I’ve commit a different content inside the title.txt
file so the check would trigger the Campaign creation job.
The first job updated the repository files, then the campaign could be created.
The campaign has been created in Infomaniak’s service with the latest RSS entry.
And I’ve received the test !
Now let’s send the actual campaign.
Conclusion
Well, I wanted more automated but as I have some restrictions with GitHub (I don’t want to make the automation repository public) I had to deal with them. However, despite being not really complicated to setup, a fully managed service on which I would have to provide my RSS link would be better. But since I’m already indirectly paying for this one, I didn’t want to pay for another.
The last step will be to integrate the newsletter subscription form for this blog. Since I’ve already did it in my Am Writing hugo theme, it should be almost the same thing.