5 Ways To Send Email from Linux Command Line – TecAdmin

We all know the importance of emails these days for the transfer of information. There are many free email service providers that we use like gmail, yahoo, rediffmail, etc. which provides a web interface to send and receive emails. but this is not enough, sometimes we also need to send emails from the system command line. This tutorial will provide you with multiple ways to send email from the linux command line. this is useful for sending emails through our shell scripts, cronjobs, etc.

5 Ways To Send Email from Linux Command Line – TecAdmin

There are several ways to send email from the command line, but here I share some options used by most users. you can use any of the options below to send email from the linux command line.

1. using the ‘sendmail’ command

sendmail is the most popular smtp server used in most linux/unix distributions. sendmail allows you to send email from the command line. use the instructions below to send an email using the ‘sendmail‘ command.

created a file with email content:

subject: the line will be used as the subject for the email.

now send an email using the following command.

read more: install and configure sendmail on centos/rhel

2. using the ‘mail’ command

The

mail command is the most popular command for sending email from a linux terminal. use some of the following examples to send an email.

  • -s is used to define the subject of the email.
See Also:  23 Seed Catalogs You Can Request For Free (& Our 4 Favorite!)

Also, you can send an attachment with this command. use -a for mailx and -a for mailutils.

  • here -a is used for attachments. use -a for debian based systems, which uses the mailutils package.

you may face a problem: bash: mail: command not found

Also, we can add comma separated emails to send the email to multiple recipients together.

3. using the ‘mutt’ command

mutt is basically used to read emails from linux terminals from local user mailboxes, it is also useful to read emails from pop/imap servers. the mutt command is somewhat similar to the mail command. use some of the following examples to send an email.

send an email with an attachment

4. using the ‘ssmtp’ command

ssmtp allows users to send email from the smtp server from the linux command line. for example, to send an email to the user [protected email] use the following command. now write the email subject as below with keyword subject. then write your message to send it to the user, after finishing your message press ctrl+d (^d) to send the email.

read more: how to configure ssmtp server on linux

5. using the ‘telnet’ command

In my experience, all sysadmins use the telnet command to test remote port connectivity or log in to the server remotely. Most of the linux newbies don’t know that we can also send emails using telnet, which is the best way to solve email sending problems. An example of sending an email is shown below.

See Also:  How to delete all emails from Gmail the smart way | Expert Reviews

the text marked in red is the user input and the rest are the responses of those commands.

additional tips: attach a file to email from shell

You can also send an email with an attachment from the linux shell. use the -a option to provide a file path with the mail command.

Thank you for using this article. we will add more shapes soon with this list. we also ask you to help me with more commands that you know and that are not listed above.

Leave a Reply

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