Linux Reader
Access files and folders on Ext, UFS, HFS, ReiserFS, or APFS file systems from Windows

Pew Pew madafakas!

Access files and folders on Ext, UFS, HFS, ReiserFS, or APFS file systems from Windows
Last updated: Jul 29, 2021

How to Use a Shell Script to Send an Email

Email is old, yet is one of the most used means of communication. People can send documents, media, files, etc. via email. Let’s see how you can send an email using shell scripting. However, before an email can go through, you must connect to a mail server.

Here you will find out:

  • how to send an email with a shell script
  • how to use "mail", "sendmail" and "mutt" command
  • when DiskInternals can help you

Are you ready? Let's read!

How can a shell script help you to send an email?

There are quite many ways to send emails if you’re running Linux. You can send an email from the command line or using a shell script. It is possible to create multiple automated scripts and schedule when they should run using the crontab command.

Now, there is no possible way to monitor if the automated scripts execute successfully or not. Thus, most people add the email command so as to receive emails about the status of their automated scripts.

A simple bash script to send an email

Here’s a simple example of a bash script that will send an email message to an identified email address.

A bash script to send an email

In the script above, the address is the default UNIX/Linux hostname used for logging in. Thus, it serves as the sender’s address. For example, if you logged in with "example.com," and then you specified “subject” in the FROM_ADDRESS: line, the final sender’s address will be subject@example.com.

This is the actual code to send this email:

The actual code to send an email

Where –s is used to specify the mail’s subject.

How to attach files using a “mail” command

It is possible to include attachments in your email. Here’s the command to add attachment(s) to an email message.

-a is used for mailx and -A for mailutils (for Debian-based systems)

Example:

Mail command to add attachment

Example:

Using mail command to add attachment

Above, the script contains up to three other email addresses that the message should also be sent to. So, you have to set these other email addresses for “carbon copying”.

Use “sendmail” command

Another way to send email messages on a Linux system is by using the “sendmail” command. This is one of the most common email-sending commands used by Linux system operators. However, you will have to install the “sendmail” program to be able to run this command.

Install with this command: $ Sudo apt install ssmtp

After installation, you can now send the email using the command below:

Sendmail command to send email

Here, the email message is saved in a file named “mail.txt.” The email message already contains the email subject and body.

Use “mutt” command to send email

Using “mutt” command, you can send an email on a Linux system. But “mutt” is used mainly to read emails on a terminal from local user mailboxes, POP, or IMAP servers. To install “mutt”, run this command:

Mutt command to send an email

Example 1:

Use mutt command to send an email

Example 2:

Example of using mutt command to send an email

If you wish to attach a file, then add the –a variable:

Attach a file

Open Linux files in Windows

Some people don't know it is possible to access files on a Linux partition when operating Windows. Using DiskInternals Linux Reader, you can not only view all your Linux partitions, but you can also access the files saved inside. It provides access to different file systems Ext2/3/4, ReiserFS, Reiser4, HFS, HFS+, FAT, exFAT, NTFS, ReFS, UFS2, RomFS(reader), ZFS (preview only*), XFS (preview only*), Hikvision NAS and DVR (preview only*)). DiskInternals Linux Reader is a handy software tool with a simple interface that is straightforward to use.

With DiskInternals Linux Reader installed on your dual-boot PC or virtual machine, it is very easy to access your Linux files at any time.


Related articles

FREE DOWNLOADVer 4.18, WinUpgrade to PROFrom $29.95

Please rate this article.
53 reviews