Once nice feature that most NAS's have is the ability to monitor themselvesFor example, run regular SMART tests on the disks, check if a disk is starting to fill up, etc. and send out notification emails.
Of course, our bPi won't be able to send out emails if it's not online, so what we need to do is set up an email relay on a computer that has an internet connection, then configure the bPi to send its emails via that.
Installing the email relay
E-MailRelay is a minimal email relay that fits our requirements nicely.
Download and install the software from here - it's a simple ZIP file that just needs to be unpacked somewhere.
Configuring the email relay
For now, we'll run E-MailRelay from the console, to get things working, then later we'll look at how to get it to start automatically when the machine boots up.
E-MailRelay is configured mostly via command-line options, so let's start setting things up.
By default, E-MailRelay logs to the Event Log, so let's change that to log to the console, and add timestamps to the log messages:
Next, we want to configure E-MailRelay to allow connections from other machines. Since it will be accepting emails from the bPi, it needs to function as an SMTP server and so, by default, accepts connections on port 25. However, since this computer is also connected to the internetIt has to be, since we want it to be able to send out emails., we'll change this port to something differentThis is because the internet is constantly being scanned for email servers that can be used to send spam. Using a different port doesn't completely protect us from this, but every little bit helps..
--remote-clients --port 1234
The --remote-clients switch allows connections from any remote computer, so let's lock that down and only accept connections from the bPi. Create a file somewhere that looks like thisIf you want to let any computer on the internal network use this service, you can change the IP address to 10.0.0.*.:
NONE server 10.0.0.2 _unused_This 4th field is required, but ignored.
If you also want to require a username/password to connect, add the following line:
LOGIN server <username> <password>
We also need to tell E-MailRelay where to find this file:
Next, we tell E-MailRelay where to relay the emails to, so that they will actually get sentE-MailRelay is a relay, not an email server i.e. it doesn't actually send emails, it simply forwards them on.:
Your email server will almost certainly require a username/password, so this needs to be configured in a file somewhereThis can be the same file as the server authentication file we created earlier.:
LOGIN client <username> <password>
And we tell E-MailRelay where to find this file:
Finally, we need to create a directory where E-MailRelay can temporarily store emails until they are successfully relayed, and tell it where this directory lives:
We also want E-MailRelay to relay emails as soon as they are receivedThe documentation says to use --immediate for this, but this gives a warning and suggests to use --poll 0 instead.:
Our final command looks like thisWe need to redirect stderr since while E-MailRelay logs to there, for some reason, it doesn't appear on the console.:
c:\bin\EmailRelay\EmailRelay.exe ^ --port 1234 ^ --forward-to myserver.com ^ --poll 0 ^ --remote-clients ^ --server-auth C:\bin\EmailRelay\auth.txt ^ --client-auth C:\bin\EmailRelay\auth.txt ^ --spool-dir C:\temp\EmailRelay-spool ^ --log --log-time ^ 2>c:\temp\EmailRelay.log
And the secrets configuration file:
NONE server 10.0.0.2 _unused_ LOGIN client BanaNAS@myserver.com password
Run this command, and E-MailRelay should just sit there, waiting for a connection.
Open the firewall
Configuring the Banana Pi
Click on Send a test email, and you should see E-MailRelay log the request, some files momentarily appear in the spool directory, before it forwards the email on to your email server.
It's also nice to be able to send emails from the command-lineFor example, to send out notifications after running automated scripts. using the mail command, so to enable this, add a .mailrc file to your home directory:
Starting E-MailRelay when the computer boots up
We want E-MailRelay to always be available, so we need to have it start every time the Windows computer is rebooted.
To do this, create a file called emailrelay-start.bat in the E-MailRelay directory, that contains the startup command we generated earlier, in a single line. Then run the following command from an administrative console:
This will create a Windows service that will start every time the Windows computer boots up.
|« Setting the current time on a Banana Pi without an internet connection||Tutorial index||Backing up a Banana Pi »|
[ + ]
|1.||↵||For example, run regular SMART tests on the disks, check if a disk is starting to fill up, etc.|
|2.||↵||It has to be, since we want it to be able to send out emails.|
|3.||↵||This is because the internet is constantly being scanned for email servers that can be used to send spam. Using a different port doesn't completely protect us from this, but every little bit helps.|
|4.||↵||If you want to let any computer on the internal network use this service, you can change the IP address to 10.0.0.*.|
|5.||↵||This 4th field is required, but ignored.|
|6.||↵||E-MailRelay is a relay, not an email server i.e. it doesn't actually send emails, it simply forwards them on.|
|7.||↵||This can be the same file as the server authentication file we created earlier.|
|8.||↵||The documentation says to use --immediate for this, but this gives a warning and suggests to use --poll 0 instead.|
|9.||↵||We need to redirect stderr since while E-MailRelay logs to there, for some reason, it doesn't appear on the console.|
|10.||↵||Run "Windows Firewall with Advanced Security", not the simple "Windows Firewall".|
|11.||↵||For example, to send out notifications after running automated scripts.|