Help Center
How to send emails via SSH?
Sending emails from the command line in Linux is a valuable skill for system administrators and developers. It allows you to send notifications, logs, or files from a remote server without the need for graphical interfaces.
Connect to the Server via SSH
Open a terminal on your local machine and connect to the remote server using SSH:
$ ssh user@server_ip_address
Replace user
and server_ip_address
with your username and the server's IP address or domain.
Send a Simple Email
Use the mail
command to send an email:
$ echo "Message body" | mail -s "Email subject" recipient@example.com
- "Message body": The content of the email.
- "Email subject": The subject that will appear in the email.
- recipient@example.com: The recipient's email address.
Example:
$ echo "Hello, this is a test email." | mail -s "Test Email" example@example.com
Send an Email with an Attachment
To send an email with an attachment, you can use mutt
or uuencode
.
Using mutt
First, install mutt
if you don't have it:
$ sudo apt install mutt
Then, send the email:
$ echo "Message body" | mutt -a /path/to/file -s "Email subject" -- recipient@example.com
Using uuencode
and mail
Install sharutils
if necessary:
$ sudo apt install sharutils
Then, send the email:
$ uuencode /path/to/file filename | mail -s "Email subject" recipient@example.com
Sending emails from the command line via SSH is a straightforward task that can automate many processes. With the right tools and this tutorial, you should be able to send emails from your Linux server without any issues.
Related articles
- Screen command in CentOs: more efficient sessions
- Solution: 'Service Unavailable' on CloudLinux servers
- Database export via command line
- Protect your data: configure RAID notifications with S.M.A.R.T.
- List CronJobs for all cPanel users
- Delete unnecessary files from the /tmp partition
- Change reserved disk space in CentOS
- Know your hardware: get accurate information on CentOS 7
- Basic SSH commands
- Optimize accounts with manual rearrange
- IP blocking in CSF via command line
- Clear DNS cache: solution to resolution problems
- Change file permissions via command line
- How to open and close ports using CSF in WHM?
- How to Modify the Hosts File in Windows, Linux, and macOS
- How to Use Telnet to Test SMTP Connectivity on Port 25
- Adjusting reserved space on Linux disks
- Adjusting reconstruction speed in RAID on Linux
- Where are NGINX logs stored?
- Configuring RAID failure notifications with mdadm
- Differences between Legacy VPS and Cloud VPS
- Install cPanel in your server or VPS
- Manage screen session