Sunday

Linux Tip: Configuring Sendmail to use Gmail as an SMTP Server

[Update 03102010]

My linux server recently suffered a hardware failure and had to be rebuilt.   I had to setup this up again and rain into issues.   I found another article which is much more straightforward.

http://www.linuxarticles.org/2010/09/relay-email-using-gmail-account-shell-prompt/

[/Update]

Wireless networking is pretty much common place these days. I've been using it at home for a number of years now and have been using security from day 1. Today I noticed that my Linksys router forgot my Wireless Security settings, leaving me exposed. I have no idea how long i've been open so needless to say i'm not pleased.

I have a script which polls my router and if my ip address has changed, it updates my dynamic dns account. So I thought it should be pretty easy to write a script to check my wireless security settings.

The script was pretty simple:

#!/bin/sh

cd /scripts

wget https://192.168.1.1/WL_WPATable.asp --http-user=admin \
  --http-passwd=admin --no-check-certificate
success=`grep "\"wpa_personal\" selected" WL_WPATable.asp | wc -l`

if [ $success -ne 1 ]; then
mailx -s "WIRELESS SECURITY DISABLED" MyEmailAddr@mydomain.com <<EOF
Please check wireless security settings.  There seems to be a problem.
EOF

echo "WIRELESS SECURITY DISABLED!!"
fi
rm WL_WPATable.asp



Note: Notice the rm command at the end of the script. You need to do this if your using wget because if it detects the page your trying to download already exists it appends a version number to the end. ie. WL_WPATable.asp.1 If this happens, your script won't be checking the right file.

Pretty simple script, the only problem is, I didn't receive an email. My linux server is on my home network, which doesn't have an smtp server and I believe they are blocked by my ISP anyways.

I found a webpage which describes how to configure sendmail to use gmails smtp server.

A correction and addition. He mentions to "Create or edit the /etc/authinfo file and with this codes". However if you cut and paste his instructions the path placed in sendmail.mc for this file is

FEATURE(`authinfo’, `Hash -o /etc/mail/authinfo’)dnl

So make sure you create authinfo in the same location. Towards the end he mentions to execute the make command. If you don't have the sendmail source this will not work for you. So instead of:

make all install restart

use:

[root@stockade mail]# m4 sendmail.mc > sendmail.cf
[root@stockade mail]# /etc/init.d/sendmail restart

Note: Any email now sent from your server will be from your gmail account. I've sent the emails to my phone and gmail account, so if my wireless security gets disabled again i'll know right away.

Anyways, thought it may be useful.

1 comment:

Sridevi Koduru said...

Regards
Sridevi Koduru (Senior Oracle Apps Trainer Oracleappstechnical.com)
LinkedIn profile - https://in.linkedin.com/in/sridevi-koduru-9b876a8b
Please Contact for One to One Online Training on Oracle Apps Technical, Financials, SCM, Oracle Manufacturing, OAF, ADF, SQL, PL/SQL, D2K at sridevikoduru@oracleappstechnical.com | +91 - 9581017828.