July 14, 2026 · 7 min read
How to send a text message from a script (bash, cron, Python) in 2026
For years, the one-liner that texted you from a script was an email to a carrier gateway — something like echo "disk full" | mail 5551234567@vtext.com. It was free, needed no API, and worked from any box that could send mail.
That trick is dead. The carriers shut the gateways down (see the per-carrier status), so those emails now vanish silently. The good news: the approach still works — you just send the email to an address that still turns it into a text. Here’s how to do that from bash, cron, PowerShell, and Python.
The one-time setup
Create an endpoint in EmailToTxt and copy its unique inbound address — it looks like server-room-a1b2c@alerts.emailtotxt.com. Add the phone number(s) that should receive the texts. Anything your script emails to that address arrives as an SMS. That’s the only new piece; the rest is mail you already know how to send.
Bash (with a working mail command)
If the host has mail or sendmail configured (or a local MTA like Postfix relaying to a smarthost), it’s a one-liner:
# subject becomes the text; keep it short and specific
echo "Backup finished with errors on $(hostname)" \
| mail -s "Backup FAILED: $(hostname)" server-room-a1b2c@alerts.emailtotxt.comNo local mailer? Send authenticated SMTP directly with curl:
curl --ssl-reqd smtps://smtp.gmail.com:465 \
--mail-from you@gmail.com \
--mail-rcpt server-room-a1b2c@alerts.emailtotxt.com \
--user 'you@gmail.com:APP_PASSWORD' \
-T <(printf 'Subject: Disk 90%% full: %s\n\nAct now.\n' "$(hostname)")Use an app password, not your account password — see the setup guides for getting one from Gmail or Outlook.
Cron
Cron is just bash on a schedule — wrap any of the above in a script and text yourself only when something is wrong, so you’re not paged for success:
# /etc/cron.d/disk-check — text only when the root FS crosses 90%
*/15 * * * * root use=$(df --output=pcent / | tail -1 | tr -dc '0-9'); \
[ "$use" -ge 90 ] && echo "root FS ${use}% on $(hostname)" \
| mail -s "Disk alert: $(hostname)" server-room-a1b2c@alerts.emailtotxt.comPowerShell (Windows)
On Windows, Send-MailMessage is built in. (It’s marked legacy by Microsoft, but it’s perfect for a quick internal alert; for new tooling, MailKit is the modern alternative.)
$cred = Get-Credential # or build a PSCredential from a stored app password
Send-MailMessage `
-From "you@outlook.com" `
-To "server-room-a1b2c@alerts.emailtotxt.com" `
-Subject "Service stopped: $($env:COMPUTERNAME)" `
-Body "The print spooler service is not running." `
-SmtpServer "smtp-mail.outlook.com" -Port 587 -UseSsl -Credential $credPython (standard library only)
Python’s built-in smtplib needs no pip install and runs anywhere Python does:
import smtplib, socket
from email.message import EmailMessage
msg = EmailMessage()
msg["Subject"] = f"Job failed on {socket.gethostname()}"
msg["From"] = "you@gmail.com"
msg["To"] = "server-room-a1b2c@alerts.emailtotxt.com"
msg.set_content("Nightly ETL exited non-zero. Check the logs.")
with smtplib.SMTP_SSL("smtp.gmail.com", 465) as s:
s.login("you@gmail.com", "APP_PASSWORD")
s.send_message(msg)Drop that in a try/except around whatever you’re monitoring and you have SMS alerting in a dozen lines, with no third-party dependency.
Why email beats an SMS API here
You could call a messaging API instead — and if you’re building a product around texting, you probably should. But for “text me when this script breaks,” email wins on effort: every OS, language, and scheduler can already send it; there are no API keys or secrets to rotate in yet another place; and you don’t have to register A2P 10DLC or handle opt-outs yourself. EmailToTxt handles the compliant SMS delivery, STOP/HELP, and rate limiting on the other side, so your script stays a script.
Frequently asked questions
- Why not just email number@vtext.com from my script like before?
- Because the carrier gateways are gone. T-Mobile’s tmomail.net stopped in late 2024, AT&T shut down txt.att.net in June 2025, and Verizon’s vtext.com is heavily filtered with a full shutdown set for March 31, 2027. Scripts that email those addresses now fail silently.
- Do I need an SMS API like Twilio to text from a script?
- Not necessarily. An API works but means credentials, A2P registration, and per-message billing in your code. If your script (or its host) can already send email — and almost every OS and language can — emailing an email-to-SMS address is less code and nothing new to maintain.
- Can I do this from a cron job with no dependencies?
- Yes. If the machine has a working mail command or a local MTA, a one-line mail invocation in cron is enough. Otherwise a few lines of Python’s built-in smtplib (or PowerShell) send authenticated mail with no extra packages.
- Will the whole email body become the text?
- No — EmailToTxt parses the alert and sends a short, readable line, trimming long content to fit a single SMS. Keep your subject or first line meaningful and that’s what lands.
Get camera alerts back on your phone
NVRtxt turns your NVR’s alert emails into clean SMS texts to any phone, over compliant 10DLC messaging. Point your recorder at a unique address and you’re done.
