Table of Contents
Mailx is a lightweight command-line email client used on Ubuntu servers for sending system alerts, notifications, and test emails.
Step 1: Update the System
Before installing Mailx, update your package list to make sure you get the latest stable version.
sudo apt update
Step 2: Install Mailx Package
Ubuntu provides Mailx through the official repositories, making installation quick and safe.
sudo apt install mailutils -y
Step 3: Verify Mailx Installation
After installation, confirm that Mailx is available on your system.If installed correctly, the version information will be displayed.
mailx -V
Step 4: Send a Test Email Using Mailx
Testing ensures Mailx works properly on your Ubuntu system.Replace [email protected] with your actual email address.
echo "This is a test email" | mailx -s "Mailx Test" [email protected]
Step 5: Check Mail Logs (If Email Fails)
If the email does not arrive, check mail logs for troubleshooting.This helps identify SMTP or configuration issues.
sudo tail -f /var/log/mail.log
Step 6: Configure SMTP (For External Email)
To send emails through services like Gmail or external SMTP servers, Mailx must be configured in /etc/mail.rc.
sudo nano /etc/mail.rc
Basic example:
set smtp=smtp://smtp.example.com:587
set smtp-auth=login
set smtp-auth-user=username
set smtp-auth-password=password
set [email protected]
