On a QNAP NAS a script needs to send a email.
In the bash test script I use msmtp. It works so far as I can tell fine but….
This is the log
--> MAIL FROM:<[email protected]>
--> RCPT TO:<[email protected]>
--> RCPT TO:<[email protected]>
--> DATA
<-- 250 2.1.0 Ok
<-- 250 2.1.5 Ok
<-- 250 2.1.5 Ok: Recipient already accepted
<-- 354 End data with <CR><LF>.<CR><LF>
Why the double RCPT and 250 2.1.5? How can I fix this.
The code to send is the following.
readonly LOGFILE=/var/log/autorun.log
readonly smtp_server="smtp.myhost.net"
readonly sender_email="[email protected]"
readonly receiver_email="[email protected]"
readonly password="PaSswOord"
send_email() {
local subject="$1"
local body="$2"
local logfile="$LOGFILE"
echo "$(date) -- begin processing email --" >> "$LOGFILE"
(
echo "From: $sender_email"
echo "To: $receiver_email"
echo "Subject: $subject"
echo
echo "$body"
echo
echo "Log excerpt:"
tail -n 20 "$logfile"
) | msmtp --debug --from="$sender_email" -t "$receiver_email"
}
echo "$(date) -- begin processing --" >> "$LOGFILE"
# Get the main script name and PID
main_script_name=$(basename "$0") # Gets the name of the main script
main_pid=$$
echo "$(date) -- The main script $main_script_name has started executing with PID: $main_pid.nnDetails can be found in the log file at $LOGFILE." >> "$LOGFILE"
# Prep an email of this start
subject="Starting Main Script: $main_script_name (PID: $main_pid)"
body="The main script $main_script_name has started executing with PID: $main_pid.nnDetails can be found in the log file at $LOGFILE."
# Send email
send_email "$subject" "$body"
The msmtp settings file in /opt/etc/msmtprc
# Example for a system wide configuration file
# A system wide configuration file is optional.
# If it exists, it usually defines a default account.
# This allows msmtp to be used like /usr/sbin/sendmail.
account default
# The SMTP smarthost
host smtp.myhost.net
port 587
from [email protected]
auth on
user [email protected]
password PaSswOord
tls on
# Use TLS on port 465. On this port, TLS starts without STARTTLS.
port 465
tls on
tls_starttls off
# Construct envelope-from addresses of the form "[email protected]"
# Do not allow programs to override this envelope-from address via -f
allow_from_override off
# Always set a From header that matches the envelope-from address
set_from_header on
# Syslog logging with facility LOG_MAIL instead of the default LOG_USER
syslog LOG_MAIL
Maybe not that important but like to have it solved.
Any suggestions here?
Is there a way to add a Reply to the mail itself and in the config file?
Also is there a way to hide the password?
1