Skip to main content

mail

Installation

sudo apt install mailutils        # [On Debian, Ubuntu and Mint]
sudo yum install mailx            # [On RHEL/CentOS/Fedora and Rocky Linux/AlmaLinux]
sudo emerge -a mail-client/mailx  # [On Gentoo Linux]
sudo pacman -S mailutils          # [On Arch Linux]
sudo zypper install mailutils     # [On OpenSUSE]  

Text Mail

echo "MAIL BODY" | mail -s 'MAIL SUBJECT' receiver@domain_name

# Enter DOT or Ctrl-d to exit the CLI
mail -s "Test mail" receiver@domain_name

HTML Mail

mailx

NOTE: Doesn't work with Notes mail client

echo "<b>HTML Message goes here</b>" | mail -s "$(echo -e "This is the subject\nContent-Type: text/html")" receiver@domain_name
sendmail
echo "FROM: info@mediasystemsfl.com
To: $email
Subject: $subject
Content-Type: text/html; charset=utf-8

<!DOCTYPE html>
<html><head>
<title>$subject</title>
<body>
<pre>
### Attention: Do not reply to this message. ###

$(Show_head)

$(Gen_asr_report)

NOTE: The symbol '<<<' indicates an ASR(Answer-Seizure Ratio) of less than $thre%. 

</pre>
</body>
</html>
" | /usr/sbin/sendmail -t

 

Functions


# Show_head & Gen_asr_report are custom functions.
Send_mail() {
    subject="This is Mail Subject"
    email="user@email.com"
    echo -e "
### Attention: Do not reply to this message. ###

$(Show_head)

$(Gen_asr_report)

NOTE: The symbol '<<<' indicates an ASR(answer-seizure ratio) of less than $thre%.
    " | /usr/bin/mail -s "$subject" "$email"
}