| by Arround The Web | No comments

Sending EmailsSend them from Linux Terminal?

Send them from Linux Terminal

Does your job require sending a lot of emails on a daily basis? And you often wonder if or how you can send email messages from the Linux terminal.

This article explains about 6 different ways of sending emails using the Linux terminal. Let’s go through them.

sendmail Command

Use the sendmail command to send emails to one or more people at once. Sendmail is one of the most popular SMTP servers in Linux. You can easily send emails directly from the command line using the sendmail command. To route the information, the sendmail command makes use of the network configured on your system. 

Let’s execute the following commands to create a file having email content.

cat /tmp/email.txt

Subject: Terminal Email Send

Email Content line 1

Email Content line 2

The Subject will be the line used as a subject for the email.

Now, to send the email, use the following syntax.

sendmail user@example.com  < /tmp/email.txt

mail Command

Just like Sendmail, you can use the mail command for sending emails from the terminal. Use the below-given command for this purpose.

mail -s "Test Subject" user@example.com < /dev/null

Here -s defines the email subject. 

To send an attachment included within the email, type the below-mentioned line.

mail -a /opt/backup.sql -s "Backup File" user@example.com < /dev/null

Here -a is used to include attachments. If yours is a Debian-based distro, use -A because it uses the mailutils package.

If you have to send emails to multiple recipients at a time, add comma-separated emails in the following manner.

mail -s "Test Email"  user@example.com,user2@example.com < /dev/null

mailx Command

The GNU Mailutils is a combination of multiple utility packages. All Mailutils can operate on mailboxes starting from UNIX maildrops, maildir, and all the way up to remote mailboxes. These mailboxes are accessed with IMAP4, POP3, and SMTP. Mailutils is made for developers, regular Linux users, and system administrators. 

For the installation purpose, use the following command.

sudo apt install mailutils

The mailutils package is mainly made of 2 commands, mail and mailx, and they both function in a similar manner.

Share Button

Source: Linux Journal - The Original Magazine of the Linux Community

Leave a Reply