能否通过Linux命令行发送SMS短信?求最优低成本实现方案
Hey there, great questions! Let’s break this down clearly—yes, you absolutely can send SMS from the Linux command line, and there are legitimate, up-to-date methods that avoid the sketchy outdated or scammy tools you’ve run into.
1. Is sending SMS via Linux CLI still possible?
Short answer: Definitely. The key is using established, trusted tools/services instead of the questionable scripts or "free SMS" sites that might be out of date or malicious. There are multiple reliable approaches depending on your needs and budget.
2. Optimal, Low-Cost Implementation Methods
Here are the best options ranked by cost-effectiveness and reliability:
Option 1: GSM Modem + Gammu/Gnokii (Lowest Long-Term Cost)
If you plan to send SMS regularly, this is the most cost-effective choice—you pay a one-time fee for a GSM USB dongle (around $20-$50) and use free open-source tools afterward with no recurring costs.
Steps to set up:
- Get a GSM USB dongle (compatible with your carrier, unlocked works best) and insert a SIM card with active service.
- Install the
gammutool (most distros have it in repos:sudo apt install gammufor Debian/Ubuntu,sudo dnf install gammufor RHEL/Fedora). - Configure Gammu by creating
~/.gammurcwith your device details:[gammu] device = /dev/ttyUSB0 # Adjust this to your dongle's port (check with `dmesg` after plugging in) connection = at baudrate = 9600 - Test and send an SMS with:
gammu sendsms TEXT +1234567890 -text "Hey, this is a test SMS from my Linux CLI!" - Alternative: Use
gnokiiif Gammu doesn’t play nice with your dongle—similar workflow, just different commands.
Option 2: Carrier Email-to-SMS Gateways (Free, But Limited)
Most mobile carriers let you send SMS via email for free by sending a message to a carrier-specific email address tied to the phone number. This is great for one-off or occasional use with zero cost, but has limitations.
How it works:
- Look up the email gateway for the recipient’s carrier (e.g., AT&T:
[phone-number]@txt.att.net, Verizon:[phone-number]@vtext.com, T-Mobile:[phone-number]@tmomail.net). - Use a command-line email tool like
muttorsendmailto send the message:echo "Quick SMS from Linux!" | mutt -s "" +1234567890@txt.att.net - Caveats: Messages are often limited to ~160 characters, some carriers might filter messages from unknown senders, and you need to know the recipient’s carrier upfront.
Option 3: Third-Party SMS APIs (Reliable, But Paid)
If you don’t want to deal with hardware and need features like batch sending, delivery status tracking, or carrier agnosticism, services like Twilio, Plivo, or Nexmo (Vonage) are solid choices. They charge per message (usually a fraction of a cent per SMS) and have simple CLI-friendly APIs.
Example with Twilio (using curl):
curl -X POST "https://api.twilio.com/2010-04-01/Accounts/YOUR_ACCOUNT_SID/Messages.json" \ -u "YOUR_ACCOUNT_SID:YOUR_AUTH_TOKEN" \ --data-urlencode "To=+1234567890" \ --data-urlencode "From=+0987654321" # Your Twilio phone number --data-urlencode "Body=SMS sent via Linux CLI using Twilio!"
- Note: You’ll need to sign up for an account to get your SID, auth token, and a Twilio phone number, but most services offer free trial credits to test.
Final Recommendations
- For regular, long-term use: GSM modem + Gammu is the best low-cost, reliable option.
- For occasional free use: Carrier email-to-SMS gateways work, just be aware of limitations.
- For scalability and no hardware: Third-party APIs are worth the small cost if you need advanced features.
Avoid any "free SMS" scripts or services that ask for your personal info or SIM card details—those are almost always scams or will stop working quickly.
内容的提问来源于stack exchange,提问作者Ryan Fredez

