wallacebrf / Synology-SMART-test-scheduler

Scheduler of Synology SMART tests
1 stars 1 forks source link

Support msmtp as well as ssmtp #3

Closed 007revad closed 4 days ago

007revad commented 1 week ago

My Asustor NAS does not have ssmtp. Instead it has msmtp. Apparently ssmtp is not maintained anymore and people should use msmtp instead.

I changed this line:

#use_ssmtp (value =0) or use mail plus server (value =1) ${7}

to:

#use_ssmtp (value =0) or use mail plus server (value =1) or use_msmtp (value =2) ${7}

and added:

elif [[ ${7} -eq 2 ]]; then #use "msmtp" command
    if ! command -v msmtp &> /dev/null #verify the msmtp command is available 
    then
        echo "Cannot Send Email as command \"msmtp\" was not found"
    else
        local email_response=$(msmtp "${1}" < "${3}/${4}"  2>&1)
        if [[ "$email_response" == "" ]]; then
            echo -e "\nEmail Sent Successfully" |& tee -a "${3}/${4}"
        else
            echo -e "\n\nWARNING -- An error occurred while sending email. The error was: $email_response\n\n" |& tee "${3}/${4}"
        fi  
    fi

This resulted in the following message:

WARNING -- An error occurred while sending email. The error was: msmtp: account default not found in 
/usr/builtin/etc/msmtp/msmtprc

So I added my email address as the default as well as my ISP's SMTP server settings in /usr/builtin/etc/msmtp/msmtprc

007revad commented 1 week ago

Yay! msmtp works with your existing SMART_email_contents.txt.

Nimbustor - Disk /dev/sdd SMART test Canceled by user

14:53:23 - 
Disk: /dev/sdd
Model: WD120EFBX-68B0EN0
Serial: redacted
User Capacity:    12,000,138,625,024 bytes [12.0 TB]

Extended SMART test was canceled by the user.
Disk Status: PASSED
wallacebrf commented 1 week ago

great news, i will definitely roll these changes into the main branch.

for the purposes of the readme file, can you confirm the only steps needed are:

open and edit /usr/builtin/etc/msmtp/msmtprc

set

# Set a default account
#account default: user@gmail.com
account default: me@email.com

and add the needed SMTP server settings?

wallacebrf commented 1 week ago

i believe the bash script portion of the project is complete. this weekend i will proceed with building the HTML/PHP web-interface

i will update the README file once i have confirmed details on using msmtp

007revad commented 6 days ago

The script is looking really good.

You missed double quoting $next_scan_time_window on line 188

Apparently in Linux the msmtprc file can be either:

In Asustor's ADM it's:

By default my msmtp file contained:

# Set default values for all following accounts.
defaults
timeout 15
tls on
tls_trust_file /usr/builtin/etc/msmtp/ca-certificates.crt
#logfile ~/.msmtplog

# The SMTP server of the provider.
#account user@gmail.com
#host smtp.gmail.com
#port 587
#from user@gmail.com
#auth on
#user user@gmail.com
#password passwd

# Set a default account
#account default: user@gmail.com
wallacebrf commented 4 days ago

readme file updated with instructions and details on using msmtp