Sending E-mails with a Raspberry Pi 2

My school needs a server that sends emails automatically every day. I know how to send an e-mail with Java. So I thought it would be okay if I just use a Raspberry Pi 2 for this little task.

My question is, whether or not it is possible to run a Java application on the Raspberry Pi that sends the E-mail every morning at 09:00 AM? Is there another programming language that would suit better for this spefic task?

Answer

If you have a Java program that sends the e-mail already, then you can use a cron job to run the command on your Pi every morning at 9:00 AM.

Cron is a program that comes pre-installed on most UNIX-like operating systems, including Linux, and it simply runs a given command at intervals you specify. Cron is always running in the background, so you don’t need to call it directly, but you do need to edit a file to schedule your Java program to be run.

As root on your Raspberry pi, run the command crontab -e to open your crontab file for editing. Then, add a line like this to the bottom, substituting the path I have given with the absolute path to your Java program.

0 9 * * * java -jar /path/to/your/program.jar

That will cause your Pi to run your Java program every single day at 9:00 AM, as long as the Pi is running. This is a programming language-independent way of running commands at intervals, so the only thing your Java program must know how to do is send the correct e-mail whenever it is run.

Leave a Reply

Your email address will not be published. Required fields are marked *