Awasu » Sending emails from a Banana Pi without an internet connection
Sunday 4th October 2015 6:42 PM []

Once nice feature that most NAS's have is the ability to monitor themselves[1]For 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.

Logging

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:

    --log --log-time
Remote connections

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 internet[2]It has to be, since we want it to be able to send out emails., we'll change this port to something different[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..

    --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 this[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.*.:

    NONE server 10.0.0.2 _unused_[5]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:

    --server-auth c:\bin\EmailRelay\auth.txt
Email server

Next, we tell E-MailRelay where to relay the emails to, so that they will actually get sent[6]E-MailRelay is a relay, not an email server i.e. it doesn't actually send emails, it simply forwards them on.:

    --forward-to myserver.com

Your email server will almost certainly require a username/password, so this needs to be configured in a file somewhere[7]This 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:

    --client-auth c:\bin\EmailRelay\auth.txt
Spool directory

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:

    --spool-dir C:\temp\EmailRelay-spool 

We also want E-MailRelay to relay emails as soon as they are received[8]The documentation says to use --immediate for this, but this gives a warning and suggests to use --poll 0 instead.:

    --poll 0
Summary

Our final command looks like this[9]We 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

We also need to open the firewall[10]Run "Windows Firewall with Advanced Security", not the simple "Windows Firewall". to allow incoming connections.

Configuring the Banana Pi

We now need to configure the Banana Pi to send emails to E-MailRelay. In the System/Notification tab of the OMV web admin interface, configure the connection details for E-MailRelay.

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-line[11]For 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:

    smtp=10.0.0.10:1234

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:

    emailrelay-service.exe --install

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.
Have your say