If you are using Linux Desktop Operating System and do not want to set up an email server, use GMail account to relay emails. On Desktop OS, we can use GUI Email Clients, which supports POP3/IMAP to send an email but how about /usr/bin/mail or from cmd prompt?
To fulfil your requirement, you need to install a simple program called ssmtp. It accepts a mail stream on standard input with recipients specified on the command line and synchronously forwards the message to the mail transfer agent of a mail hub for the mail hub MTA to process. Failed messages are placed in dead.letter in the sender’s home directory.
STEP 1: Installation,
# yum install ssmtp -y
STEP 2: Configure gmail account for relay,
# nano /etc/ssmtp/ssmtp.conf
Add/Edit below lines:
Save and exit the file.
STEP 3: Also, make sure you disable Sendmail:
# service sendmail stop; chkconfig sendmail off
# mkdir /root/.backup
# mv /usr/sbin/sendmail /root/.backup
# ln -s /usr/local/ssmtp/sbin/ssmtp /usr/sbin/sendmail
STEP 4: Now, you can use “mail” command to send email messages.
# echo “This is a test” | mail -s “Relay Test” email@example.com