Send Emails to Yourself to Update Debian-Based Machines
WORK IN PROGRESS - INSTRUCTIONS UNFINISHED
Securing your homelab should be your top priority. One effective measure to bolster security is to regularly update both your server and its virtual machine instances whenever security patches become available. While setting up a cronjob to handle system updates is an option, integrating MSMTP into your setup can significantly enhance both your homelab experience and its overall security by informing you what packages are available to install via email. Let's delve into how MSMTP can transform your homelab management, especially in keeping you informed about impending updates.
What you will need to know or have:
- MSMTP
- Google Mail Account
- BASH scripting
- HTML
- Cron
Steps:
- Setup Google App Access
- Install and Configure MSMTP
- Send Email via BASH script
- Automation using Cronjob
Setup Google App Access
We need to configure our Google account to use App Passwords to allow MSMTP to authenticate and use its email address and SMTP gateway to send emails.
To enable App Password you have to setup a 2nd Multi-Factor Authentication.
Once enabled hhyou can create an App Password and we will use this 16 character password in our configuration file later
Install and Configure MSMTP
Install MSMTP (Debian, Ubuntu)
$ sudo apt-get install msmtp Create msmtp configuration file in your home directory
$ sudo vim ~/.msmtprc
Contents of .msmtprc file:
# Set default values for all following accounts.
defaults
auth on
tls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
logfile ~/.msmtp.log
# Gmail
account gmail
host smtp.gmail.com
port 465
tls_starttls off
from USERNAME@gmail.com
user USERNAME
password PASSWORD
# Set a default account
account default: gmailSend test notification email to your email address
$ echo "Test" | msmtp -a default USERNAME@gmail.com
You should have receieved an email to the specified email address in the command above
Send Email via BASH script
We will create a BASH script that will insert text data we retrieve from updating commands into an HTML file. Once created we will send it using MSMTP.
#!/bin/bash
Edit permissions on configuration file
$ echo "Test" | msmtp -a default USERNAME@gmail.com Edit permissions on configuration file
Automation using Cronjob
Edit permissions on configuration file
$ echo "Test" | msmtp -a default USERNAME@gmail.com
Comments
Post a Comment