Send a mail in a script

I need to send a message from a command in a script.

Someone knows if it is posible and how to do ?

Thank you!

https://www.google.co.uk/search?q=unix+mail+command+line

Plenty of help to be found…

cpt_paranoia wrote:
https://www.google.co.uk/search?q=unix+mail+command+line

Plenty of help to be found…

Hi, I know the command but it will need to install an important quantity of new packages to run it.

I supposed that MyCloud has a way to send a mail because it send it with events and I will want to use this capacities.

Some help?

I was trying the same thing a while ago. In the end I found that there are 2 ways to use WD’s built-in mail service

  • Make your own custom error code in ( Change en_EN to whatever language you are using)

    /etc/nas/strings/en_EN/alertmessages.txt

 For example add a new rule 3000 with your e-mail text, you can then send a mail to the e-mail adress configured in the UI by using the following command in shell:

/usr/local/sbin/sendAlert.sh 3000

 The downside of this method is that your e-mail text isn’t changeable from within your script (or you need your script to edit alertmessages.txt each time beforehand)

  • You can also make use of the send function in:

    /var/www/rest-api/lib/pear/includes/Mail/sendmail.php

 This requires multiple modifications of this file. I can’t remember exactly how I achieved this, but I know it’s possible! This was the hardest way, but when I got it working, it was the “cleanest” way in my opinion to get dynamic email text…

Unfortunately, in the mean time, I bricked my drive a couple of times and never bothered configuring the mail client again, so I can’t look up my edits… I’m sure there are more ways to achieve this, but I stopped looking after getting sendmail.php to work

1 Like

joskevermeulen wrote:

I was trying the same thing a while ago. In the end I found that there are 2 ways to use WD’s built-in mail service

 

  • Make your own custom error code in ( Change en_EN to whatever language you are using)

/etc/nas/strings/en_EN/alertmessages.txt

 For example add a new rule 3000 with your e-mail text, you can then send a mail to the e-mail adress configured in the UI by using the following command in shell:

 

/usr/local/sbin/sendAlert.sh 3000

 The downside of this method is that your e-mail text isn’t changeable from within your script (or you need your script to edit alertmessages.txt each time beforehand)

  

joskevermeulen, first at all, thanks for your comment.

This is what I was looking for. It is enough for me. It is in the good way and allow me to find the solution.

The final solution is:

  • Insert a row in “alertdesc” table that is in “/CacheVolume/.wd-alert/wd-alert-desc.db”. I did it in other linux because I did not knew do it in myCloud.
  • Insert the descriptiĂłn of the message in /etc/nas/strings/es_ES/alertmessages.txt. Depends of your language.
  • Insert the code and a textual descriptiĂłn /etc/nas/alert-param.sh. (perhaps this is no necesary).

After that, you can use /usr/local/sbin/sendAlert.sh xxxx to send a message

Just to add, you could also use interpreter modules to send smtp meassages. Or another way is to install sendmail-esmtp (though you’ll need to first install for v3 firmwares or build for v4 firmwares). Then setup your smtp server/user/pass and trigger this from the shell or script. I’m using them for php/perl/python/shell scripts so the mails are directly sent from my ISP instead of WD.

echo -e "To:recipient@host.com\nFrom:me@host.com\nSubject:hello\n\nMy Messages" | sendmail recipient@host.com

Nazar78 wrote:

Just to add, you could also use interpreter modules to send smtp meassages. Or another way is to install sendmail-esmtp (though you’ll need to first install for v3 firmwares or build for v4 firmwares). Then setup your smtp server/user/pass and trigger this from the shell or script. I’m using them for php/perl/python/shell scripts so the mails are directly sent from my ISP instead of WD.

 

echo -e “To:recipient@host.com\nFrom:me@host.com\nSubject:hello\n\nMy Messages” | sendmail recipient@host.com

 

Nazar78, thanks for that idea. I will to try to use it.