How to utilize the command line in Linux to send an email

This article teaches you how to use the commonly used mail commands for sending emails. It is equally important to learn how to send attachments with Linux emails. The commands mentioned include some command line options.

  • -s: denotes the mail’s subject
  • -a: for denoting attachment
  • -c: for the copy email address (CC)
  • -b: for the blind copy email address (BCC)

How to send emails from the command line using Linux

In Linux, we will be taught about the various commands used to send emails.

    1. One option for paraphrasing could be:

– Postal service
– Postbox
– Email client
– Packaging and sending emails
– Email delivery

1. Employing the mail Command

The Linux mail command is widely used and popular for sending emails from the command line. On Debian systems, it is installed as part of the mailutils package, while on Redhat systems, it is installed as part of the mailx package. Both commands handle messages within the command line. To install mailutils on Debian and Ubuntu Systems, simply execute the following command.

$ sudo apt install mailutils -y

To execute the command on CentOS and RedHat distributions:

$ yum install mailx
Internet Site option mail command

Trying out the Mail command.

To check if the mail command is properly installed, test the application by following this format and pressing enter:

$ mail –s "Test Email" email_address

substitute “email_address” with the email address of your choice. For instance,

$ mail –s "Test Email" james@example.com
Linux send email example
$ echo "sample message" | mail -s "sample mail subject" email_address

let’s say for instance,

$ echo "Hello world" | mail -s "Test" james@example.com
Linux email with subject
$ mail -s "subject" -A message.txt email_address

The file is attached using the -A flag. For instance;

$ mail -s "Important Notice" -A message.txt james@example.com
Linux email with attachment
$ mail –s "test header" email_address email_address2

2. Employing the mailx command.

Mailx, previously known as nail in other systems, is an updated version of the mail command. It has been in existence since 1986 and was included in POSIX in 1992. Mailx is included in Debian’s mail package, which is utilized in multiple scenarios. This mail utility can be employed by users, system administrators, and developers. The syntax of the mailx implementation is similar to that of the mail command line. To install mailx on Debian/Ubuntu Systems, execute the following command.

$ sudo apt install mailx

To install mailx on RedHat & CentOS, you can run the following command:

$ yum install mailx

Can you please verify the functionality of the Mailx command?

Here is one option for paraphrasing the sentence:

“To avoid being prompted for CC and the message body, you can utilize the echo command to send the output directly to the mail command, as demonstrated in this example.”

$ echo "message body" | mail -s "subject" email_address

For instance,

$ echo "Make the most out of Linux!" | mail -s "Welcome to Linux" james@example.com

3. Employing the MUTT Command

To install Mutt on Debian / Ubuntu Systems, execute the following command:

$ sudo apt install mutt

To install mutt on Redhat / CentOS Systems, execute the command:

$ sudo yum install mutt

Trying out the Mutt command.

Using mutt, you have the option to send a message without any content by appending < /dev/null immediately after specifying the email address.

$ mutt -s "Test Email" email_address < /dev/null 

Let’s say, for instance,

$ mutt -s "Greetings" james@example.com < /dev/null 
Mutt Blank Email
$ echo "Message body" | mutt -a "/path/to/file.to.attach" -s "subject of message" -- email_address

for instance,

$ echo "Hey guys! How's it going ?" | mutt -a report.doc -s "Notice !" -- james@jaykiarie.com
Mutt Email File Attached

4. The mpack command should be utilized.

To encode the file into MIME messages and send them to one or multiple recipients, or to post them to various newsgroups, you can utilize the mpack command. To install mpack on Debian/Ubuntu Systems, proceed with the following instructions:

$ sudo apt install mpack 

To install mpack on Redhat / CentOS Systems, execute the following command:

$ sudo yum install mpack

Please try out the mpack command for testing purposes.

Sending email or attachments via command line using mpack is extremely straightforward.

$ mpack -s "Subject here" -a file email_address

Let’s take an instance, for instance.

$ mpack -s "Sales Report 2019" -a report.doc james@jaykiarie.com
Linux Mpack Send Email Attach File

5. Employing the sendmail function

To add sendmail, which is another widely used SMTP server, to Debian/Ubuntu Systems, execute the following command:

$ sudo apt install sendmail

To install sendmail on RedHat/CentOS Systems, execute the following command:

$ sudo yum install sendmail

Attempting to send a test email using the sendmail command.

To send an email using the sendmail command, you can follow these provided guidelines.

$ sendmail email_address < file

As an illustration, I have generated a document named report.doc containing the subsequent text.

Hello there !

The instruction for delivering the message will be,

$ sendmail < report.doc james@example.com
Sendmail Output

Could you please provide the sentence or passage that needs to be paraphrased?

Using command line email clients is less complex and does not require as much processing power. However, it is limited to sending emails only to personal email domains, excluding Gmail and Yahoo domains due to additional authentication requirements. Additionally, receiving emails from external SMTP servers is not possible. To avoid issues with undelivered emails, it is generally recommended to use GUI email clients such as Thunderbird or Evolution.

 

 

More tutorials

SSH Example Tutorial for Expect Script(Opens in a new browser tab)

Using Telnet Commands in Linux/Unix(Opens in a new browser tab)

Installation of Arch Linux(Opens in a new browser tab)

React Application Component Testing Integrate with Playwright(Opens in a new browser tab)

The main method in Java(Opens in a new browser tab)

 

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds