How to Send mail using Command line interface in Linux.

Linux mail command is a command-line utility that allows to send emails from the command line.We can send mail using semdmail or mailutils package.Sendmail is a email routing facility used for email transport over the Internet. It use SMTP (Simple Mail Transfer Protocol) for the mail-transfer and email delivery.

Install the mailutils package.

Update the system.

apt-get update

Install the mailutils.

apt install mailutils  

Type Y.

four postfix options are available for installation.Select Internet site.

Fig 1

Provide System mail name.Click Ok.

Fig 2

Send mail.

mail -s "Subject" <recipient address>  

Sendmail with mail body.

mail -s "subject" <recipient_address> <<< 'Message'  

Sendmail with message from a file.

mail -s "Hello World" [email protected] < /home/mail/mailcontent.txt  

Sendmail with CC and BCC.

mail -s "Hello World" <recipient address> -b userto< bcc address>  
or
mail -s "Hello World" <recipient address> -c userto< cc address>  
or
mail -s "Hello World" <recipient address> -b userto< bcc address> -c userto<cc address>  

Sendmail to multiple recipients.

mail -s "Hello World" <recipient address1>,<recipient address2>  

 

Install the Sendmail package.

update the system.

apt-get update

Install Sendmail

apt-get install sendmail

Find your hostname.

hostname

Configure /etc/hosts file.

vim /etc/hosts

Add the hostname.

127.0.0.1 localhost hostname

Run Sendmail’s config

sendmailconfig

Type Y.

Restart Apache

service apache2 restart

Send an email.

sendmail -v [email protected]

Provide a From address.

From: [email protected]

Type a subject.

Subject: Subject of message

Type the message.

example

To send the email, type a ‘.‘ (dot) on the empty line and press enter.

.

 

 

Leave a Reply

Your email address will not be published.