File Upload/Change Email Notification

Currently reading
File Upload/Change Email Notification

1
1
Operating system
  1. macOS
Mobile operating system
  1. Android
Hey everyone,

I'm struggling with an issue with this script I found online and tweaked slightly to my own needs. Unfortunately this script was dependent on GMail allowing the less secure apps to connect. My emails stopped June 2nd which seems to coincide with their May 30th sunset date.

Is there a way to tweak this to send mail with Googles API? Or am I better off using another mail service? I started looking into whats needed to make the API calls but it doesnt look like it will be as easy of a change as I was thinking.

Has anyone been able to send emails through user scripts with Google's new security change?

I would really appreciate any help on this!

Ryan

Code:
##### Sends email to users when defined folder has been modified.

##### If the defined folder has not been modified, an email can be sent to the admin by setting SEND_UNCHANGED to 1.

##### Comparison lists can be recursive or not, depending on RECURSIVE_LIST parameter value.

##### Comparison is only performed on file names, and not contents.

##### During the first run, creates lists for comparison and store them in '/homes/admin/_nasData_scripts' folder (see REP_DATA parameter)

##### TODO: send diffence list as attachment, as too large string sent in mail body can cause empty mail!

##### ------------------------------------ user's parameters

EXPLORE_FOLDER="/volume1/path/to/folder/Dropbox"

# Separate multiple users by comma in USERS_MAIL_LIST. Example: "[email protected],[email protected]"

USERS_MAIL_LIST="[email protected]"

ADM_MAIL="[email protected]"

FROM_MAIL="[email protected]"

RECURSIVE_LIST=0

SEND_UNCHANGED=0

##### ------------------------------------ advanced parameters

REP_DATA="/volume1/path/to/file/_nasData_scripts_notification"

FOLDER_SHORT_NAME="$(basename "$EXPLORE_FOLDER")"

CURR_FILE="_"${FOLDER_SHORT_NAME//[,; :*+&#~\/\"\'\(\)\\]/}_curr_list.txt

PRIOR_FILE="_"${FOLDER_SHORT_NAME//[,; :*+&#~\/\"\'\(\)\\]/}_prior_list.txt

EMAIL_TITLE="NAS Update
"

EMAIL_INTRO=""

##### ------------------------------------

USERS_MAIL_LIST="$ADM_MAIL,$USERS_MAIL_LIST"

RESULT_ALL=""

RESULT_ADM=""

# --------- collecte des paramètre pour retour admin

PARAMS="Parameters:

    EXPLORE_FOLDER: $EXPLORE_FOLDER

    FOLDER_SHORT_NAME: $FOLDER_SHORT_NAME

    REP_DATA: $REP_DATA

    CURR_FILE: $CURR_FILE

    PRIOR_FILE: $PRIOR_FILE

    RECURSIVE_LIST: $RECURSIVE_LIST

    SEND_UNCHANGED: $SEND_UNCHANGED"

# --------- creation REP_DATA pour fichiers CURR_FILE & PRIOR_FILE

mkdir -p "$REP_DATA"

if [ ! -d "$REP_DATA" ]; then

    /usr/bin/php -r "mail('$ADM_MAIL', '$EMAIL_TITLE: error', 'Error : unable to create $REP_DATA folder.', 'From: $FROM_MAIL');";

    exit

fi

if [ ! -d "$EXPLORE_FOLDER" ]; then

    RESULT_ADM="NAS folder \'$FOLDER_SHORT_NAME\' error.

Unable to locate folder \'$EXPLORE_FOLDER\'


$PARAMS"

    /usr/bin/php -r "mail('$ADM_MAIL', '$EMAIL_TITLE: error', '$RESULT_ADM', 'From: $FROM_MAIL');";

    exit

fi

# --------- écriture du contenu du dossier passé dans CURR_FILE

if [ "$RECURSIVE_LIST" != 0 ]; then

    ls --ignore-backups --ignore="*Thumbs.db*" --ignore="@eaDir" --ignore="*@SynoResource" --recursive "$EXPLORE_FOLDER"> "$REP_DATA/$CURR_FILE"

else

    ls --ignore-backups --ignore="*Thumbs.db*" --ignore="@eaDir" --ignore="*@SynoResource" --recursive "$EXPLORE_FOLDER"> "$REP_DATA/$CURR_FILE"

fi

# --------- comparaison PRIOR_FILE et CURR_FILE

if [ -f "$REP_DATA/$PRIOR_FILE" ]; then

    # --------- le fichier 'prior' existe : comparaison possible

    DIFF_LIST=$(diff --ignore-file-name-case --unchanged-group-format="" --old-group-format="
-------- %dn file%(n=1?:s) added:
%<" --new-group-format="
-------- %dN file%(N=1?:s) deleted:
%>" --exclude="*.db" "$REP_DATA/$CURR_FILE" "$REP_DATA/$PRIOR_FILE")

    if [ "$DIFF_LIST" != "" ]; then

       DATA_TO_SEND=${DIFF_LIST//\'/\\\'}

       DATA_TO_SEND=${DATA_TO_SEND//\"/\\\"}

       RESULT_ALL="$DATA_TO_SEND"

    else

      if [ "$SEND_UNCHANGED" != 0 ]; then

         RESULT_ADM="NAS folder \'$FOLDER_SHORT_NAME\' is unchanged.


$PARAMS"

       fi

    fi

else

    # --------- alerte de création des fichiers

    RESULT_ADM="NAS folder \'$FOLDER_SHORT_NAME\' analysis:


File \'$REP_DATA/$CURR_FILE\' has been created.


$PARAMS"

fi

# ----------- copie de liste actuelle (CURR_FILE) pour comparaison future

cp "$REP_DATA/$CURR_FILE" "$REP_DATA/$PRIOR_FILE"

# ----------- envoi email a l'admin ou aux utilisateurs

if [ "$RESULT_ALL" != "" ]; then
RESULT_ALL="$FOLDER_SHORT_NAME folder changed."
   /usr/bin/php -r "mail('$USERS_MAIL_LIST', '$EMAIL_TITLE', '$EMAIL_INTRO $RESULT_ALL', 'From: $FROM_MAIL');";

else

   #/usr/bin/php -r "mail('$ADM_MAIL', '$EMAIL_TITLE', '$RESULT_ADM', 'From: $FROM_MAIL');";

exit

fi
 
I'm very interested with this script, if someone is able to tune this script, I'm very interested and OK to talk about collaboration...

Send me message if interested by the job.

Thx
 
Upvote 0

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

Similar threads

  • Question
Sorry. I gave up and moved on.
Replies
5
Views
3,502
I find that the lowest brightness level is bright enough for me so my schedule doesn't change: 0700 LEDs...
Replies
6
Views
1,776
  • Locked
Sure, no tutorial then. Delete the thread all I care. Bye!
Replies
13
Views
7,977

Welcome to SynoForum.com!

SynoForum.com is an unofficial Synology forum for NAS owners and enthusiasts.

Registration is free, easy and fast!

Back
Top