Help Center

How to send emails via SSH?

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.

Let’s get started!

Start TODAY for just $3.45/mo

Includes website builder, 30 GB cloud storage, 200+ apps and professional email.

Intuitive control panel
24/7 support
Website builder
Get Started

30‑day money‑back guarantee