Code Examples

August 30, 2026 · View on GitHub

Ready-to-run, production-ready examples for mx.msgwing.com:465 (SSL/TLS) or :587 (STARTTLS), one file per language — all in the GitHub repository:

LanguageFile
Pythonpython-zerosmtp.py
PHP (PHPMailer)php-zerosmtp.php
PHP (Symfony Mailer)php-symfony-mailer-zerosmtp.php
Node.jsnode-zerosmtp.mjs
TypeScriptts-zerosmtp.ts
Bash (curl)bash-curl-zerosmtp.sh
Bash (swaks)bash-swaks-zerosmtp.sh
Javajava-zerosmtp.java
C# (.NET / MailKit)cs-zerosmtp.cs
Gogo-zerosmtp.go
Rubyruby-zerosmtp.rb
Rustrust-zerosmtp.rs
Kotlinkotlin-zerosmtp.kt
Elixirelixir-zerosmtp.exs
Lualua-zerosmtp.lua
Perlperl-zerosmtp.pl
C (libcurl)c-zerosmtp.c
Dartdart-zerosmtp.dart
Zig (libcurl)zig-zerosmtp.zig
Swiftswift-zerosmtp.swift
PowerShellpwsh-zerosmtp.ps1

The Elixir, Lua and Dart examples were contributed by @slegarraga in #83, #84 and #85. Every example here is run in CI on each change, so a language nobody on this project writes daily stays correct rather than quietly rotting.

Missing a language you use? A working example is a genuinely useful contribution and it gets credited here by name.

Deployment recipes

Not every migration is a code change — often the SMTP settings live in a configuration management tool or a container definition instead:

RecipeFileWhat it does
Ansibleansible-zerosmtp.ymlPoints a fleet's system mailer (cron, unattended-upgrades, systemd OnFailure=) at the relay via msmtp. See Linux setup for the manual equivalent.
Docker Composedocker-compose-zerosmtp.ymlSends one message from a container, reading credentials from .env.
GitHub Actionsgithub-actions-zerosmtp.ymlEmails a workflow's own failures through the relay via dawidd6/action-send-mail, so a broken deploy or a quietly-stopped scheduled job doesn't go unnoticed. Testable on demand via workflow_dispatch, without waiting for a real failure.

Each example reads credentials from ZEROSMTP_* environment variables (ZEROSMTP_USERNAME, ZEROSMTP_PASSWORD, ZEROSMTP_FROM, ZEROSMTP_TO, ZEROSMTP_SUBJECT) — never hardcode real credentials into a script.

See the Quickstart for how to get @msgwing.com credentials, and Troubleshooting if a send hangs or fails.