For example, if you automate some processes like backup, database dump, ... you may be interested in sending reports by email straight from your batchs.
This article will explain how to configure your NAS to be able to send emails from command line.
The sendmail client used will be the one provided by the NAS firmware : msmtp.
Configuration will be done to be able to use a Gmail account, but it can obviously be adapted to any other smtp provider.
This article has been tested on DNS-323 running Fun plug 0.5 and on DNS-325 running Fun plug 0.7. It should also be applicable to a DNS-320 as well.
1. Configuration file
Email account configuration and log files will be held under /ffp/etc/msmtp.
The configuration file will hold all the needed information about the account used to send mails.
Important : It has to be accessible by the root user only (600), otherwise msmtp will refuse to use it.
So, here are she steps to create the environment files & directories :
# mkdir -p /ffp/etc/msmtp
# touch /ffp/etc/msmtp/msmtp.conf
# chmod 600 /ffp/etc/msmtp/msmtp.conf
# nano /ffp/etc/msmtp/msmtp.conf
The configuration file has to follow the msmtp specifications.
If you are using a gmail account, your /ffp/etc/msmtp/msmtp.conf configuration file should be like that :
# Set gmail default values
# Gmail account parameters
# set log file
2. Send a mail
When the configuration file is ready, you should be able to send a mail.
First thing to do is to prepare a mail body file.
It should be in a text file, for example under /ffp/tmp/mail.txt, and it should have the following structure :
Subject:Subject of the mail
Your email body starts here ...
Please note that it is very important to have one empty separation line between the Subject and the body.
If not, your mail will be sent, but without body.
Once the email file is prepared, to send it you just need to throw the following command line :
# cat /ffp/tmp/mail.txt | /usr/bin/msmtp --file=/ffp/etc/msmtp/msmtp.conf --read-recipients
Your mail has been sent … that's as simple as that !
You can check that it has been successfuly sent in /ffp/etc/msmtp/msmtp.log.
Dec 04 16:17:01 host=smtp.gmail.com tls=on auth=on user=xxx from=xxx recipients=xxx mailsize=102 smtpstatus=250 smtpmsg='250 2.0.0 OK 1323012020 x12sm48350372eef.9' exitcode=EX_OK
You are now ready to automatise a lot of tasks on your DNS-32x and to get some feedback & reporting by email.
Hope it helps.
- DNS 320 & 325 - Extend your NAS possibilities with Funplug 0.7
- DNS 325 - Funplug 0.7 : Install Transmission p2p client
- DNS 325 - Funplug 0.7 : Install Twonkymedia Server 7
- DNS 323 & 325 - Funplug : Send mail from shell scripts using your Gmail account
- DNS 325 - Funplug 0.7 : Move Fun plug to a USB key
- DNS 320 & 325 - Funplug 0.7 : Install Compilation Environment
- DNS 325 - Funplug 0.7 : Compile x264, lame, shine, fdk-aac, twolame, ffmpeg and sox
- DNS-325 - Funplug 0.7 : Subsonic server with realtime MP3 and AAC transcoding
- DNS 325 - Funplug 0.7 : SSLH ... share port 443 for Https, Ssh, OpenVPN and Tinc
- DNS 325 - Funplug 0.7 : Administrate your NAS with Ajaxterm
- DNS 325 - Funplug 0.7 : Supervise your NAS thru SNMP
- DNS 325 - Funplug 0.7 : Supervise Fan Speed and Case & HDD temperature with SNMP
- DNS 320, 323 & 325 - Funplug 0.7 : Install a Munin node with Muninlite
- DNS 325 - Funplug 0.7 : Setup your NAS as a Permanent BTSync Peer
- DNS 320L - Funplug 0.7 : Supervise Fan Speed and Case & HDD temperature with Munin
- DNS 320 & 325 - Funplug 0.7 : Update wget to handle latest SSL & TLS