Code Examples

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:

Language File
Python python-zerosmtp.py
PHP (PHPMailer) php-zerosmtp.php
PHP (Symfony Mailer) php-symfony-mailer-zerosmtp.php
Node.js node-zerosmtp.mjs
TypeScript ts-zerosmtp.ts
Bash (curl) bash-curl-zerosmtp.sh
Bash (swaks) bash-swaks-zerosmtp.sh
Java java-zerosmtp.java
C# (.NET / MailKit) cs-zerosmtp.cs
Go go-zerosmtp.go
Ruby ruby-zerosmtp.rb
Rust rust-zerosmtp.rs
Kotlin kotlin-zerosmtp.kt
Elixir elixir-zerosmtp.exs
Lua lua-zerosmtp.lua
Perl perl-zerosmtp.pl
C (libcurl) c-zerosmtp.c
Dart dart-zerosmtp.dart
Zig (libcurl) zig-zerosmtp.zig
Swift swift-zerosmtp.swift
PowerShell pwsh-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:

Recipe File What it does
Ansible ansible-zerosmtp.yml Points a fleet’s system mailer (cron, unattended-upgrades, systemd OnFailure=) at the relay via msmtp. See Linux setup for the manual equivalent.
Docker Compose docker-compose-zerosmtp.yml Sends one message from a container, reading credentials from .env.
GitHub Actions github-actions-zerosmtp.yml Emails 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.

Updated 30 Aug 2026

mx.msgwing.com587 STARTTLS · 465 SSL/TLS Register free