Sending Emails with Python on a Static Site: Overview
smtplib is the standard-library Python module that sends email over SMTP (Simple Mail Transfer Protocol), and the Gmail API is Google’s REST interface for sending mail with OAuth2 tokens instead of a stored password. This post uses both to send newsletters from a backend-less GitHub Pages site.
If you’re hoping to send email via API with no authentication at all, I’ll be upfront: no reliable method skips it entirely. Gmail’s SMTP server needs a password or app password, the Gmail API needs an OAuth2 token, and even the free tiers of transactional email APIs like SendGrid or Mailgun require an API key. That’s a deliberate anti-spam safeguard rather than an oversight, so this post focuses on the two authenticated Python methods that actually work.
Because this blog is a static website hosted on GitHub Pages (which I wrote about in my AI-Free Website Design post), I do not have a backend server. That means I cannot simply run a PHP script or a Node.js process to handle contact forms or send out newsletters.
But that hasn’t stopped me. I use a hybrid approach: a lightweight service for receiving messages, and pure Python code for sending them.
Receiving Form Submissions on a Static Site with a Form Endpoint
To handle incoming form submissions on a static site, you need an endpoint. For years, I have used UseBasin.com.
The setup is incredibly straightforward: you generate an HTML form on their dashboard, copy the action URL, and paste it into your site’s HTML. You can customise the form styling entirely with your own CSS.
I prefer it over other solutions because it handles spam filtering effectively and allows me to export my subscriber list easily. Once I download the new subscribers as a CSV file to my local machine, I am ready for the fun part: sending the emails with Python!
Sending Email Messages with Python smtplib and the Gmail API
🔒 Subscribe to keep reading.
References
🔒 Subscribe to keep reading.
Subscribe to unlock the full article ❤️
Log in to unlock
The form below signs you up for the newsletter. It does not log you into the app — log in afterwards (same email) to unlock this article and download your subscriber gifts. New subscribers get an inbox mail: Set a password to unlock articles.
Full content temporarily unavailable — refresh in a moment