What's new

Notifications (E-Mail)

  • 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!

I found some time to actually work out the syntax and a simple example for a script that will send Email notifications from your router. See this Wiki page I just added.

I know is an old post but I'm having some trouble with the Gmail method. When logging in to the root using ssh, I tried to use the 'wget' method exactly as you have posted, and get a return error stating that I cannot download the certificate without using the --no-check-certificate. Whats that all about. I assume it has something to do with connecting to the Geotrust website insecurely. Because when I use my browser in which validates secure websites, I am able to load the certificate in html form just fine. What should I do?o_O
 
I know is an old post but I'm having some trouble with the Gmail method. When logging in to the root using ssh, I tried to use the 'wget' method exactly as you have posted, and get a return error stating that I cannot download the certificate without using the --no-check-certificate. Whats that all about. I assume it has something to do with connecting to the Geotrust website insecurely. Because when I use my browser in which validates secure websites, I am able to load the certificate in html form just fine. What should I do?o_O

What it says: use the --no-check-certificate. The wget version used by the firmware has changed since that Wiki was written. Wget is unable to validate SSL certificates as it lacks the required bundle of root certificates to validate them.
 
What it says: use the --no-check-certificate. The wget version used by the firmware has changed since that Wiki was written. Wget is unable to validate SSL certificates as it lacks the required bundle of root certificates to validate them.
What would the wget command with' --no-check--certificate' look like?
 
What would the wget command with' --no-check--certificate' look like?

Whatever your wget command previously was (I don't know what it was), just add this option to it.
 
Whatever your wget command previously was (I don't know what it was), just add this option to it.

So where is the correct dir to save this script? /jffs/scripts/ or save to /tmp/???
Reason I ask, sorry I know this seems very shallow, but you stated that this script will survive reboot, but may or will not survive flashing. I noticed at the end of the bash script that 'rm /tmp/mail.txt' is used and i'm trying to wrap my head around the file being deleted at the end of the script.

P.S. I'm learning Bash Commanding Linux at the moment, forgive me if this is a stupid question. It seems easy to pick up, Python was my first language and I added learning C programming to my list as I am playing with Arduinos and Raspberry Pi's..lol :confused:

****nevermind, about the "wrap my head around the file being deleted at the end of the script" bit. The /tmp/mail.txt file is temporarily used for the instance of reboot then removed and the wan-start script should be saved to root ?????****

Also, there seems to be a problem when attempting to make a donation when clicking on the paypal button on your website lostrealm.ca. I get as far as logging into paypal using the donation button and then paypal notifies that there was a problem and cannot make the requested donation. I give you more details if you wish.

#!/bin/sh
FROM="your-gmail-address"
AUTH="your-gmail-username"
PASS="your-gmail-password"
FROMNAME="Your Router"
TO="your-email-address"

ntpclient -h pool.ntp.org -s &> /dev/null
sleep 5

echo "Subject: WAN state notification" >/tmp/mail.txt
echo "From: \\"$FROMNAME\\"<$FROM>" >>/tmp/mail.txt
echo "Date: `date -R`" >>/tmp/mail.txt
echo "" >>/tmp/mail.txt
echo "I just got connected to the internet." >>/tmp/mail.txt
echo "" >>/tmp/mail.txt
echo "My WAN IP is: `nvram get wan0_ipaddr`" >>/tmp/mail.txt
echo "Uptime is: `uptime | cut -d ',' -f1 | sed 's/^.\{12\}//g'`" >>/tmp/mail.txt
echo "" >>/tmp/mail.txt
echo "---- " >>/tmp/mail.txt
echo "Your friendly router." >>/tmp/mail.txt
echo "" >>/tmp/mail.txt

cat /tmp/mail.txt | sendmail -H"exec openssl s_client -quiet \
-CAfile /jffs/configs/Equifax_Secure_Certificate_Authority.pem \
-connect smtp.gmail.com:587 -tls1 -starttls smtp" \
-f"$FROM" \
-au"$AUTH" -ap"$PASS" $TO

rm /tmp/mail.txt
 
Last edited:
My cable modem is flapping today due to a COX issue (big supriser? :)). So I'm curious is there some way to include in our script which interface we are now on? IP is great but I don't want to think about it and would like to include something like "I'm connected to WAN" or "I'm connected to USB" or "I have switched to secondary WAN." or something ? Do we have visibility to the state status?

thank you!
 
I have no way to check them, but you might try querying the following nvram vars to see if you can deduce the status

wans_dualwan

link_wan
link_wan1

wan0_gateway
wan1_gateway
 
Is there a way to send an email when a client connects to the wifi?
It's possible to send an email from a script, as discussed in this thread and the wiki.

What you are really asking is "how do I detect when a client has connected to the Wi-Fi?" The answer to that question has been discussed at length in other threads.

UPDATE: Here's a similar question that was asked recently: http://www.snbforums.com/threads/email-on-guest-wifi-use.18814/
 
Last edited:
Thanks.

I think then I would need an if then script that uses the wl command that runs in a loop or is scheduled to run at regular intervals but I am guessing it would have to be quite complex (for me ) to pick out the specific additional client in the output and add that to the email.

I'll see what I can find.
 
Hi everybody

Any chance to get mail notification on powerloss when the router is connected to a SAI/UPS?

I have that function on my QNAP NAS and is very helpful. The only thing is that my NAS is not connected 24h/24h

It would be great to have that function scripted on my RC66U ^^

I know your post is old, but you may want to look into Network UPS Tools (NUT). I have it running on my FreeNAS but haven't researched if it can be adapted to a router.
 
I found some time to actually work out the syntax and a simple example for a script that will send Email notifications from your router. See this Wiki page I just added.
Bonjour Eric :), I used to use videotron relais.videotron.ca smtp to send e-mails with sendmail, but since mars 2016, it is not working anymore...

JANGO now offers a free account for 30 days only, do you know any other ? (unless the acount lasts more than 30 days ...)

So Gmail is the only choice left, I tried it, and it works but I have to authorise the less secure applications in my google acount settings. I tried with the original certificate you are using and the new one suggested in posting 109 " https://www.geotrust.com/resources/root_certificates/certificates/GeoTrust_Primary_CA.pem".
I will use gmail anyways.
If "allow secure apps. only" in google settings are set I get:
..............
firewall# ./gmail.sh

depth=2 C = US, O = GeoTrust Inc., CN = GeoTrust Global CA
verify error:num=20:unable to get local issuer certificate
verify return:0
250 SMTPUTF8
sendmail: failed
...............

allow less secure apps gives:
******************
firewall# ./gmail.sh

depth=2 C = US, O = GeoTrust Inc., CN = GeoTrust Global CA
verify error:num=20:unable to get local issuer certificate
verify return:0
250 SMTPUTF8
*******************
and the email goes through, it works !

Thanks for the wiki
jrb.
 
Vidéotron no longer allows relaying emails from domain that aren't @videotron.ca. The change was progressively deployed over the past couple of months.

Note that GMail also offers app-specific passwords. You could use that capacity to generate a password dedicated to your outgoing notifications. I don't know if they still require you to globally enable access from less-secure applications, or if it's a selective bypass.
 
Note that the original Wiki page that I wrote has been extensively modified by users since my original page, so I'm not up to speed as to the latest methods.
 
Hmmm... I don't use a cert with my email scripts going over to GMail - instead I use SASL, which Gmail supports with most email clients, no cert needed.

I use the secure SMTP port for them, which is smtp.gmail.com:587

Someone could probably tweak a script for that one - just need to have a valid gmail account and password...
 
Here's my full SASL config for postfix

Code:
# See /usr/share/postfix/main.cf.dist for a commented, more complete version

# TLS parameters
smtp_use_tls = yes
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

myhostname = testbox
relayhost = [smtp.gmail.com]:587

# SASL Parameters
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options =

Again, we're using Gmail, so note that the username/pass aren't in main.cf, they'll be in another file…
Code:
sudo nano /etc/postfix/sasl_passwd
add the following line

Code:
[smtp.gmail.com]:587    gmailuser@gmail.com:gmailpassword

gmailuser/gmailpassword is the userid/pass for the gmail account that we're using

Now we fix perms and update the postfix config to use the sasl_passwd file
Code:
sudo chmod 400 /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwd

And we then reload postfix

Code:
sudo service postfix reload

To test - the following should generate an email from your server to your gmail inbox - yes, this <line> is deliberately <broken> for a <reason> - if you don't remove the <brackets> - you'll get an error

Code:
echo "Test mail from postfix" | mail -s "Test Postfix" <gmailuser>@gmail.com

So having this info, someone should be able to create a script around this for AsusWRT...
 
Vidéotron no longer allows relaying emails from domain that aren't @videotron.ca. The change was progressively deployed over the past couple of months.

Note that GMail also offers app-specific passwords. You could use that capacity to generate a password dedicated to your outgoing notifications. I don't know if they still require you to globally enable access from less-secure applications, or if it's a selective bypass.
But I'm with Videotron.ca, it should work.
 
But I'm with Videotron.ca, it should work.

But is the From: field also using an address @videotron.ca? This is a new requirement (and I suspect the address must also exist on their servers).
 
Similar threads

Similar 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