Managing a remote server often requires a way to receive automated notifications without a graphical interface. You might be running long-duration scripts and need a way to get notified upon completion, or you might want to receive unattended-upgrades reports directly in your inbox to maintain system health. Without a terminal-based email solution, you risk missing critical security alerts or hardware failures.
Ubuntu provides several powerful mechanisms to send mail directly from the command line, ranging from simple notification agents to full-scale transfer services. Whether you are automating a backup script or need to check file size in Linux and mail the results to a colleague, the terminal offers efficient tools to integrate communication into your workflow. This guide explains the best methods to get mail flowing from your shell.
Table of Contents
Key Takeaways: Terminal Email Essentials
- MUA (Mail User Agent) → The client software (like
ssmtpormail) that you use to compose and send the message. - MTA (Mail Transfer Agent) → The background service (like Postfix) that handles the routing and delivery of the email.
- Postfix → The default MTA for Ubuntu, compatible with legacy
sendmailcommands. - TLS Encryption → Essential for security to ensure that your passwords and message content are not sent in plain-text over the network.
- Sudo Privileges → Administrative rights are required to install and configure mail services to ensure Linux server security.
Method 1: Using sSMTP for Minimalistic Sending
For most users who only need to send alerts from scripts, sSMTP is the ideal solution. It is a minimalistic client that forwards mail from your terminal to an external mail server (like Gmail or an enterprise relay) without hosting a full mail server locally.
Installation: sudo apt install ssmtp
Usage Example: echo "Subject: Test Mail" | ssmtp [email protected]
This method is highly efficient because it does not run a persistent background daemon, saving system resources while still providing reliable delivery.
Method 2: Configuring Postfix (The Ubuntu Standard)
Postfix is the default supported Mail Transfer Agent in Ubuntu. It is robust, secure, and designed to handle professional-grade mail traffic. It is the best choice if you need a persistent service to handle mail for multiple users or complex routing.
Installation: sudo apt install postfix
Configuration Details: During installation, a configuration menu will appear. For basic terminal sending, select “Internet Site” and enter your Fully Qualified Domain Name (FQDN). You can trigger this menu manually later using: sudo dpkg-reconfigure postfix
Method 3: Verifying Connectivity with telnet
If your emails are not arriving, you can manually test your connection to the mail server to see if Port 25 (the standard SMTP port) is blocked or open.
See also: Mastering the Linux Command Line — Your Complete Free Training Guide
Command: telnet mail.example.com 25
Expected Output:
220 mail.example.com ESMTP Postfix
ehlo mail.example.com
250-STARTTLS
250 8BITMIME
If you see “Connected,” your network path is clear. If it hangs, your ISP or firewall settings may be blocking outbound mail traffic.
Step-by-Step Process: Setting Up Postfix for Local Sending
Follow these steps to configure the standard Ubuntu mail service for your local environment:
- Open your terminal and ensure your system is up to date with
sudo apt update. - Install the package by running
sudo apt install postfix. - Choose “Internet Site” when the configuration wizard appears.
- Enter your domain (e.g.,
mail.yourdomain.com) as the System Mail Name. - Restart the service to apply changes:
sudo systemctl restart postfix. - Send a test mail using the
mailcommand:echo "Body text" | mail -s "Terminal Test" [email protected] - Check logs if the mail fails to arrive:
sudo tail -f /var/log/mail.log.
Summary Tables
| Mail Component | Role | Recommended Tool |
|---|---|---|
| User Agent (MUA) | Compose/Send | ssmtp or mailutils |
| Transfer Agent (MTA) | Routing/Delivery | Postfix |
| Delivery Agent (MDA) | Inbox Storage | Dovecot |
| Alert Manager | Automated Alerts | Prometheus |
| Configuration Choice | Meaning | Best For… |
|---|---|---|
| Internet Site | Sends/Receives via SMTP | Production Servers |
| Satellite System | Forwards all to another host | Internal Office Nodes |
| Local Only | No external delivery | Development/Testing |
FAQs
Why is my terminal mail going to spam? Most automated mail from unknown IP addresses is flagged as spam. Ensure you have a valid SPF record or use an authenticated relay service.
Do I always need ‘sudo’ to send mail? No. You need the sudo command only for installation and configuration. Once the service is set up, any user can send mail via the CLI.
Can I send file attachments from the terminal? Yes, tools like mutt or mail -A allow you to attach files. This is useful for sending system log extracts.


