Tips & Tricks

How to send e-mail over SSH

This article will show you how to send e-mails using the command mail in unix-like operation systems. It’s tested and working on Linux and FreeBSD.

This article will show you how to send e-mails using the command mail or sendmail.

1. Sending e-mail using the mail command:
The requirements are pretty simple. You just need to have sendmail installed. Usually it comes with the most unix-like operation systems.
Let’s see what you need to send an e-mail using the command mail:
The command can be executed as any active user on the box. Here is an example for the mail sending:

Once you execute this it will give you a blank space where you can insert the text for your e-mail.
When you finish writing the e-mail you can stop the input mode with the key combination CTRL + D.
As soon as you press CTRL + D it will ask you for Cc:. If you want to send the e-mail to more than one recepient you can use this field and add the second e-mail address.
Note: You can add more than one e-mail address in the Cc: field separated by comma.
Here is an example:

This will send the e-mail to all defined e-mail addresses. There is other way to send the e-mail to multiple e-mail addresses. You can insert the e-mail addresses in the command like this:

This will be sent to all defined e-mail addresses as well.

2. Sending text file as an e-mail:
It is pretty simple to send a text file to your e-mail over the mail command.
You need to use this syntax:

This command will directly send the file contect to the desired e-mail(s) address(es).
Here is an example if you want to send the your samba configuration file to 2 e-mail addresses:

Note: This is 1-line command

That’s it! Contgratilations you know how to send e-mails over consoleĀ šŸ˜‰

Leave a Reply