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 know it's a script, I have a gmail address and I downloaded certificate in /jffs/configs.
Please just post your entire script here or update wiki (without your email and pass, of course :))
 
Last edited:
My complete script (called "mail" and in my case located in /opt/home/root) is:

Code:
#!/bin/sh
sendmail -H"exec openssl s_client -quiet \
-CAfile /opt/home/root/cert/Equifax_Secure_Certificate_Authority.pem \
-connect smtp.gmail.com:25 -tls1 -starttls smtp" \
-f"my_address@gmail.com" \
-au"my_address@gmail.com" -ap"my_gmail_password" $1

I have downloaded the Equifax certificate into the file indicated (/opt/home/root/cert/Equifax_Secure_Certificate_Authority.pem) and I used the script like:

cat content.txt | /opt/home/root/mail receipent_address@domain.com

From your text it looks as if you didn't feed sendmail any data, but the error message indicates something went wrong with the verification of the certificate.

I got the certificate from here (straight in .pem format). Just used wget to download it straight to the router.
http://www.geotrust.com/resources/root-certificates/index.html
 
Last edited:
Well, that was what I intended my first pasted line to help with. If you understand how the sendmail command works it should be easy to adapt the script. It should work with something like this.

Code:
#!/bin/sh
FROM="router@domain.com"
AUTH="account@gmail.com"
PASS="gmail_passowrd"
FROMNAME="Your Router"
TO="you@domain.com"

echo "Subject: WAN state notification" >/tmp/mail.txt
echo "From: \"$FROMNAME\"<$FROM>" >>/tmp/mail.txt
echo "Date: `date -R`" >>/tmp/mail.txt
echo "I just got connected to the Interwebz." >>/tmp/mail.txt
echo "My new IP is: `nvram get wan0_ipaddr`" >>/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 /opt/home/root/cert/Equifax_Secure_Certificate_Authority.pem \
-connect smtp.gmail.com:25 -tls1 -starttls smtp" \
-f"$FROM" \
-au"$AUTH" -ap"$PASS" $TO 

rm /tmp/mail.txt


Note: You run this script on your own risk, I haven't tried it. If I made a typo that means it bricks your router, don't blame me.
 
My point was that you should never run a scripts that you don't know how it works. And if you understand how the script works I don't understand how you did not manage to put it together yourself.
 
i tried this script and got this error
Code:
connect: Connection timed out
connect:errno=145
sendmail: helper exited (1)
#!/bin/sh
FROM="xxxx@gmail.com"
AUTH="xxxx@gmail.com"
PASS="xxxx2"
FROMNAME="Your Router"
TO="xxxx@gmail.com"

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:25 -tls1 -starttls smtp" \
-f"$FROM" \
-au"$AUTH" -ap"$PASS" $TO

rm /tmp/mail.txt
wait just figured it out. smtp.gmail.com:25 didnt work for me it kept timing out. using smtp.gmail.com:587 worked for mr
 
Last edited:
The reason might be that your ISP is blocking outgoing traffic on port 25 (spam prevention). In that case they should have a relay SMTP server set up for their clients (I know Swedish ISP Telia does this).

In that case you can use the simpler script against your ISPs SMTP server.


I don't know if my ISP even has a SMTP server... we got our fiber installed and it's working but I haven't received any information from the ISP... That's why I had to get the gmail SMTP server working.
 
this will send your syslogs to your gmail address
Code:
#!/bin/sh
FROM="x@gmail.com"
AUTH="x@gmail.com"
PASS="x
FROMNAME="Router RT-N66R"
TO="x@gmail.com"

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

echo "Subject: Router RT-N66R" >/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 "Syslogs: `cat /tmp/syslog.log | less`" >>/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:
Another script to receive HTML email notifications when a torrent has finished downloading, read wiki
I added transmissionbt picture and made torrent name in bold.
 
Last edited:
Here is a screenshot

2mi2is4.png
 
Connecting to Amazon SES and couple other tidbits

Connecting to Amazon SES:

Amazon SES requires TLS, so the previous examples for connecting to Gmail will work...with one minor change. Do not use the -crlf switch in the openssl command:

printf "Subject: $SUBJECT\nFrom: RT-N66U<noreply@mydomain.com>\n\n$MESSAGE" | sendmail \
-H"exec openssl s_client -quiet -connect email-smtp.us-east-1.amazonaws.com:465" \
-f"noreply@mydomain.com" \
-au"$xxxxxxxxxxxxxxxxxxxx" \
-ap"$xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
me@mydomain.com

Also note: I didn't find it necessary to download the CA certs and reference them like was done in the previous Gmail examples. Openssl will complain that it can't find the cert issuer, but it will still proceed.

Other notes:

printf will preserve line feeds (unlike echo which escapes them), so you can redirect a string directly into sendmail instead of writing a file to the file system:

SUBJECT="My subject"
MESSAGE="My message line 1\nLine 2 of my message\nLine 3 of my message"
printf "Subject: $SUBJECT\nFrom: RT-N66U<noreply@mydomain.com>\n\n$MESSAGE" | sendmail \
-H"exec openssl s_client -quiet -connect email-smtp.us-east-1.amazonaws.com:465" \
-f"noreply@mydomain.com" \
-au"$xxxxxxxxxxxxxxxxxxxx" \
-ap"$xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
me@mydomain.com

Also, remember that this distribution of sendmail has a verbose switch. If you are having trouble, activate it and it will probably show you why:

printf "Subject: $SUBJECT\nFrom: RT-N66U<noreply@mydomain.com>\n\n$MESSAGE" | sendmail \
-H"exec openssl s_client -quiet -connect email-smtp.us-east-1.amazonaws.com:465" \
-f"noreply@mydomain.com" \
-au"$xxxxxxxxxxxxxxxxxxxx" \
-ap"$xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
-v me@mydomain.com
 
I have the wan-start script working and sending an gamil after the reboot of the router.

Is it possible to receive an email when een open-vpn or vpn connection is made?
 
A geek question :) ...

I use S/MIME to generally sign/encrypt each of my outgoing emails. So, I'm wondering if and how it is possible to enhance the mail script in terms of encrypting the notification email with the public key of my own recipient address before it is sent?
 
Sorry for this newbie question, but how exactly can I copy a script to this '/jffs/scripts' location? How can I access, e.g. view, this location in general. Do I need a separate tool/utility for it? (I am on a Win7 machine.)

TIA!
 
Sorry for this newbie question, but how exactly can I copy a script to this '/jffs/scripts' location? How can I access, e.g. view, this location in general. Do I need a separate tool/utility for it? (I am on a Win7 machine.)

TIA!

Rather than TELNET/SSH into the RT-N66U and use the native 'vi' (or entware 'nano') editor, I enable SSH on the router, install WinSCP on Win7/8 then use WinSCP to open an 'SCP' session to the router then simply navigate in the right-pane to edit the script in /jffs/scripts;set permissions; and execute/test the scripts.

Regards.
 
Similar threads

Similar threads

Latest threads

Sign Up For SNBForums Daily Digest

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