How to Send Backups of Your Raspberry Pi Files to Your Email
Raspberry Pi is a marvel of low-cost, compact-sized computing. Its users often run critical projects or store valuable data on their devices. However, like any other computer system, Raspberry Pis are not immune to hardware failures, data losses, and other issues.
Therefore, making regular backups is essential to protect your files and data. But what if you could automate this process and, in addition, send the backups directly to your email? This article will guide you from creating a backup to installing and configuring the necessary software, scheduling the task, and finally, sending the email with the backup.
All you need is a command line email client and, of course, a Raspberry Pi board.
Create a Raspberry Pi Backup
The first step in this process is to create a backup of the files you want to protect. On Raspberry Pi, this can easily be done with the tar command. For instance, to back up the folder /home/pi/my_data, you would use the following command:
tar -zcvf /path/to/my_data_backup.tar.gz /home/pi/my_data
In the my_data folder, you might find documents, images, text files, etc. Be sure to set the correct file path both for the my_data folder and the backup archive.
Install the Necessary Software
Once you have created your backup, you will need a way to send it via email. For this, use Mutt, a command-line email client. To install Mutt on your Raspberry Pi, enter:
sudo apt install mutt
Configure the Mutt Software
After installing Mutt, you will need to configure it to send emails. Create and edit the file ~/.muttrc with the nano text editor:
sudo nano ~/.muttrc
Add the following content to it:
set from = "[email protected]"
set realname = "First Last"
# IMAP settings
set imap_user = "[email protected]"
set imap_pass = "<mailbox password>"
# SMTP settings
set smtp_url = "smtps://[email protected]"
set smtp_pass = "<mailbox password>"
# Remote Gmail folders
set folder = "imaps://imap.gmail.com/"
set spoolfile = "+INBOX"
Press Ctrl + X, then Y and Enter to save the changes.
Now let’s test check that Mutt is able to send and receive emails with this account.
echo "Body Message" | mutt -s "Testing Email from mutt" [email protected]
If the command has worked, you should check that the test message you sent has arrived.

If the command comes up with an error, “SASL Authentication Failed”, you will need to generate an app password in Gmail.
Read More: How to Send Backups of Your Raspberry Pi Files to Your Email – MakeUseOf