What's new

Sending Email fails with "05 May" date/time in header

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

alan6854321

Senior Member
I have a script that sends me an Email on WAN connected (via the wan-event script).

On loading the latest Merlin release, the Email is rejected by my ISP as the date/time in the header is the "05 May" the router has before it connects to ntp (I don't think this has anything to do with the latest release, it's the first reload for about 70 days).

The Email gets delivered fine if I reset the WAN connection later on, and according to the entry in syslog, the failing Email is sent when the time has already been set.

The method I use to send the Email I stole from a thread on here somewhere (I'm not a great script expert), this is a snippet where the Email is sent (it uses parameters set in amtm). The "Email sent" message appears in syslog with a valid date/time.

So.. how does the date/time in the Email header get set?

Code:
# ---- OK - lets send it

/usr/sbin/curl -v --url ${PROTOCOL}://${SMTP}:${PORT} \
   --mail-from "$FROM_ADDRESS" --mail-rcpt "$TO_ADDRESS" \
   --user "${USERNAME}:$(/usr/sbin/openssl aes-256-cbc "$emailPwEnc" -d -in "$amtmEMailPswdFile" -pass pass:ditbabot,isoi)" \
   --upload-file "$cemTempEMailContent" \
   $SSL_FLAG --ssl-reqd --crlf >> "$cemTempEMailLogFile" 2>&1

if [ $? -eq 0 ]
then
    rm -f "$cemTempEMailLogFile"
    rm -f "$cemTempEMailContent"
    logger Email sent: $1
else
    logger Email: FAILED to send, see $cemTempEMailLogFile
   fi

The wan-event script has the following, I think it waits for ntp to be set ..

Code:
#!/bin/sh
#
# Send Email when the WAN is restored,
# Wait for network to come up first.
#
if [[ $# -gt 1 ]] && [[ $2 == "connected" ]]
then
  ntpclient -h pool.ntp.org -s &> /dev/null
  sleep 5
  /jffs/AGT/scripts/send-wan-connected-email &
fi
 
Last edited:
Not sure this will fix your issue, but have you tried the router date feature in amtm? It will set the clock to the last known date time before the ntp server is up and running
 
Not sure this will fix your issue, but have you tried the router date feature in amtm? It will set the clock to the last known date time before the ntp server is up and running
Yeah I think it would, but I tried it before and didn't like it - made it difficult to spot the reboot in syslog.

BUT - I think I know what the problem is - my terrible scripting!

The ntpclient command I had in my wan-event script doesn't seem to exist (I guess it did in a previous release?), so it was doing nothing. I thought it was waiting until ntp was set.

I think the Email header was built while the date wasn't yet set and the the curl command actually does retries until the network came up so it looked like the whole thing happened after the date was set.
 
Do you mind posting your final working script? I've been having trouble with something similar. Thanks.
 
Can anyone tell me what the following two options in scMerlin do?

"Enable NTP boot watchdog script" - I have this disabled
"Enable NTP Ready startup check" - I have this enabled.
 
Do you mind posting your final working script? I've been having trouble with something similar. Thanks.
I just deleted the ntpclient command and increased the sleep time to 60 secs.
Works for now until someone tells me how to properly wait until ntp has been set.
 
So.. how does the date/time in the Email header get set?
Looks like you're missing some header content. Unfortunately, you did not include that portion in your post.
Make sure the Date line is included.
Code:
"Date: $(date -R)"
 
Last edited:
Looks like you're missing some header content. Unfortunately, you did not include that portion in your post which is unfortunate.
Make sure the Date line is included.
Yeah, I found that line earlier in the script, didn't realize the date was just included with the 'text' of the Email until now.
 
Looks like you're missing some header content. Unfortunately, you did not include that portion in your post.
Make sure the Date line is included.
Do you know the correct way to wait until ntp has been set?
 
Do you know the correct way to wait until ntp has been set?
Code:
ntptimer=0
ntptimeout=20
while [ "$(nvram get ntp_ready)" = 0 ] && [ "$ntptimer" -lt "$ntptimeout" ]; do
    ntptimer=$((ntptimer+1))
    sleep 1
done

if [ "$ntptimer" -ge "$ntptimeout" ]; then
    # do something else, NTP is not ready
else
    # continue with script, NTP is set.
fi
 

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top