Email alerts with smtplib and a Gmail app password
Two modes, one script
@reboot entry. One file covers both the planned alerts and the unplanned ones.App passwords, not your real password
Headers that survive spam filters
A snippet from the implementation
Straight from the example as deployed on the Server (Node-RED) — copy it freely:
def build_message(subject, body):
"""Builds the MIMEText with full headers to avoid spam filters."""
message = MIMEText(body, "plain", "utf-8")
message["Subject"] = subject
message["From"] = EMAIL_SENDER
message["To"] = EMAIL_RECEIVER
return messageThe full example is a complete program — wiring header, setup and main loop — ready to adapt to your application.
Frequently asked questions
Why email instead of a messaging app or SMS?
Email needs no extra service, no SIM and no API contract, and the support inbox is already monitored. For higher criticality you can add channels later, keeping SMTP as the baseline that always works.
Does this work with providers other than Gmail?
Yes. Any SMTP server with STARTTLS on port 587 works — change SMTP_HOST and the credentials. Gmail with an app password is simply a convenient, reliable default for small deployments.
How does Node-RED trigger the alarm emails?
The polling flow classifies each station reading into levels 0-4. Levels 3 and 4 route to a function that formats subject and body, then an exec node runs this script with both as arguments.