Swaks Email Scripting

Hi, in this blog post I will show you how I configured Swaks for sending emails using SMTP using my custom SMTP server.

First I ran the following command to install swaks:

sudo apt-get install swaks

With swaks installed, I could start building a test command just to
see if this would actually work. I started with the below command:

swaks --to destination@email.com --from source@email.com --auth --auth-user=source@email.com --auth-password=passwordforsource@email.comaccount --server smtp.example.com -tls

This gave me an error along the lines of “Could not authenticate – connection refused” after talking to the people hosting my SMTP server, I found out that I needed to make sure that I was using port 587 and not the default port of 465.

So I made sure that my command explicitly used that port by adding it to the server parameter and managed to get an email to successfully send. You can see the code I used below:

swaks --to destination@email.com --from source@email.com --auth --auth-user=source@email.com --auth-password=passwordforsource@email.comaccount --server smtp.example.com:587 -tls


I wanted to use this in a script so that I could launch the script and an email would get sent. I also wanted to change what would get sent in the actual email since currently, it was just using the default values.

After 5 or so minutes of cobbling a script together, I came up with what you can see below:



swaks --to destination@email.com \
--from=source@email.com \
--auth \
--auth-user=source@email.com \
--auth-password=password-for-source-email \
--server smtp.example.com:587 \
--body "$hostname - uptime is $uptime" \
--header "Subject: $hostname is still up" \
-tls \

Now I can send this email whenever I want, I even created a CRON job to send the email every hour. Enjoy!

Make Website Confirm Before Leaving

Long pause between blogs here but busy life = slow blog.

In this blog, I will discuss how I created a simple webpage that would allow me to leave a pinned tab open in my web browser that would create a popup box when trying to leave the site. The popup box can be seen below:

This is helpful because Chrome doesn’t give the option to make sure you actually want to close the window. So if you have ever, just like myself, been 2 hours deep into researching something that seemed really important at the time and then accidentally clicked the red X and have it all close, then you know how I feel.

So I created my own website that I would load and pin in the Chome windows so that this wouldn’t happen to me. This is the code that I used:

 window.onbeforeload = function(){
  return "Do you really want to leave?";

and the site that I created is currently live at noautoclose.mharwood.uk

Just make sure to click anywhere on the page for the script to work, enjoy!