Host this container (or your derivative) on your Paas of choice (e.g. https://heroku.com, https://render.com, https://fly.io, ...)
Given the minimal resource requirements for this project, the free or cheapest plan should suffice!
For these instructions, I'm going with https://render.com, who - at this time of writing - offer a free plan that will work just fine.
The only caveat with their free plan is that services will spin down automatically after 15 minutes of inactivity. This does, however, not mean that things will stop working - your service will spin right back up when a new request is received; it might simply take a second or 2!
From your dashboard, initiate the creation of a new Web Service by clicking the 2 buttons marked in red:
If you've connected your GitHub or GitLab account, you may choose to connect one of your own repositories (e.g. a clone of this project - or another project entirely)
But for simplicity, you can just move down the page and choose a "Public Git repository":
- Enter the url to this repository (
https://github.com/matthiasmullie/post-to-email
) - Click "Continue"
No shortage of input fields here, but
- Give your service a unique name
- You might want to choose a different region to deploy your service in, or pick a different plan (optional - these defaults will be just fine)
- Branch, Root Directory and Environment must remain as seen on the screenshot below (
main
, empty andDocker
, respectively) - Click "Create Web Service"
Your new service is now being built. Render is pulling down the code and starts building the service, which may take a couple of minutes. We're not done yet, though:
- Now click "Environment" in the left navigation column to move on to the next part
In order to be able to receive emails, you'll need to configure a couple of things, like the connection to the mail server to use, or the email recipient.
- Click "Add Environment Variable"
- Add a key called
ALLOW_ORIGIN
- As value, enter the domain you want to accept requests from (e.g.
https://my-website.com
), or*
to allow requests from anywhere- To prevent abuse, I'd recommend locking things down to a specific domain unless there's a good reason not to
- Read up on Access-Control-Allow-Origin if you want to learn more
- Click "Add Environment Variable" to add the next one
- Add a key called
DSN
(short for "Data Source Name") - As value, enter your SMTP connection string
- Click "Add Environment Variable" to add the next one
In this example, we'll also set the recipient so that any email sent through this arrives at your email address.
While it's possible to include this variable in the data your form will submit, it makes sense to hard-code some of these in the web service, to prevent others from being able to (ab)use your service.
- Add a key called
RECIPIENT
- As value, enter the email address you want to receive emails at
- This can take either
my-email@example.com
orMy Name <my-email@example.com>
format
- This can take either
- Unless you want to hard-code more settings (e.g.
ALLOW_ORIGIN
,SUBJECT
, ... - see the full list of configuration options), click "Save changes"
After having supplied the environment variables, your service will now be rebuilt once more to reflect these changes.
You can navigate back to your dashboard to find your service, which should end up with a "Deploy succeeded" status. Your service is now available at https://<your-unique-project-name>.onrender.com
.
Next up: build your static form.