Howto send email from bash on DLink DNS-323

This can be done only on hacked dns-323 ffp/fun_plug. Many people have problem sending emails from shell scripts using DNS-323, it is possible without installing additional software or writing scritps. Sending emails right from bash scripts in DNS-323 is quite easy, but it took me some time to make it work.

Software already installed on NAS

Sending mails from this device can be done using two programs which are already installed!


  1. Make sure that you have ffp/funplug installed
  2. Login to your DNS-323 (if there is no shell prompt write 5784468 to get it)
  3. Create two files /mnt/HD_a2/ffp/start/crontab_update and /mnt/HD_a2/ffp/bin/ and make it executable (read whole post)
  4. Reboot NAS, or run /mnt/HD_a2/ffp/start/crontab_update start
  5. You should be done

crontab_update init script for ffp

Location: /mnt/HD_a2/ffp/start/crontab_update
Make it executable: chmod +x /mnt/HD_a2/ffp/start/crontab_update

Contents of crontab_update:

# PROVIDE: crontab_update

# Email settings are taken from webadmin!

. /ffp/etc/ffp.subr


# You must CHANGE settings below

crontab_update_start() {
 # start with existing crontab
 /bin/crontab -l > $CRONTXT

 # add the Rsync job to execute at 2:05 am - also create a logfile
 /bin/echo "0 20 * * 1-4 /mnt/HD_a2/ffp/bin/ &" >> $CRONTXT
 /bin/echo "15 16 * * 5 /mnt/HD_a2/ffp/bin/ &" >> $CRONTXT

 # We are now booting - send test email and enable mail
 if [ ! -e /.msmtprc -o ! -e /.muttrc ] ; then
         email -m 63 -h $SMTP -p 25 -a 1 -u $USER -w $PASS -s $SOURCE -d $DEST -t
         test -e /home/root/.msmtprc && ln -s /.msmtprc /home/root/
         test -e /home/root/.muttrc && ln -s /.muttrc  /home/root/

 # install the new crontab
 /bin/crontab $CRONTXT

 # clean up tmp crontab
 /bin/rm $CRONTXT

run_rc_command "$1"

do_sth script

Location: /mnt/HD_a2/ffp/bin/
Make it executable: chmod +x /mnt/HD_a2/ffp/bin/

Contents of: /mnt/HD_a2/ffp/bin/

# Simple script to do something


echo -e "Process ended with result ===> $RESULT\n"\
"Space remaining:\n\n"\
"Your DNS-323 (dlink-storage)"\
| mutt -s "Process status ("`date -I`")"
How this can be improved?
Think about cat /tmp/ | mutt -s dlink-storage_E-Mail_Alert

How I've figured this out?

Made strings /sys/crfs/web and found email -h %s -p 25 -a 1 -u %s -w %s -s %s -d %s -t rest was just a matter of time - to get to know how to use it correct.

Common mistakes

  • Sending email option must be enabled in webclient and tested
  • Blogger sometimes changes "" to other characters (UTF-8), which Bash doesn't understand, and whole process after copying files fail - make sure that you have "" and not some other characters in files
  • If you are using Notepad or other editor without UNIX newline format support, you're in trouble - Bash also can't understand this - on Windows try to use Notepad++
  • Changing email credentials is done by web interface

Additional links


DNS-323 is very powerful device you can even turn nearly every USB printer into network enabled, it can even change USB scanner into networked scanner which is pretty cool.


I would like to post this article, as a tip on DNS-323 wiki, with link to this post - anyone registered there?


  1. Hi, in your crontab_update you should do this:

    # We are now booting - send test email and enable mail
    if [ ! -e /.msmtprc -o ! -e /.muttrc ] ; then
    email -m 63 -h $SMTP -p 25 -a 1 -u $USER -w $PASS -s $SOURCE -d $DEST -t
    test -e /home/root/.msmtprc && ln -s /.msmtprc /home/root/
    test -e /home/root/.muttrc && ln -s /.muttrc /home/root/

    Otherwise, if you have the wrong email settings a symlink will be make which will prevent the files from being written to once you have the correct settings. To get around this I had to delete the stale symlinks in /home/root and run it again. Thanks for the great info!

  2. Cool - I was looking for this for quite a while. Little mistake: In "Preparation" point 4:

    Reboot NAS, or run /mnt/HD_a2/ffp/start/crontab_update start

    The 'start' parameter is missing.

    Also you should note that of course the parameters such as "", "" etc. have to be replaced with one's own and for SMTP servers without login, both user and password can be set to "admin". The comment in your script makes it sound as if they are taken automatically from the web interface.

  3. @Anonymous: Thanks, making fix.

    @Chris: Thanks for your comment, currently I don't own a DNS-323 anymore, so I can't check it. But as far as I remember DNS-323 took settings from web interface (file: "/.msmtprc" and "/.muttrc") and send mails using this. I'll write proper comments in script and make bugfixes.

  4. Nice! I'll test this! Would be great to have the DNS-323 to send an email with the IP-address it got when starting!


Post a Comment

Popular posts from this blog

How to generate user documentation from Perl script?

35 Google open-source projects that you probably don't know

Using perl to extract files from large directory structure