Exim and Multiple Domains – PHP Mail function and junk mail issue

I am now working at a place where I get a chance to home my php, javascript and mysql skills, work with cake and other similar projects The job has System Admin work also and it is fun since I get to learn lots of new things. At the moment, I am just being given debugging and troubleshooting to do on the servers, but it is a matter of time before I impress and blow my team leader away. :D

Meanwhile, one issue that came up was a client with a server that had multiple domains on it. While sending mails with php’s mail function, the Received and other headers were not being set correctly, because of which mails to hotmail and live.com were ending up in the junk folder.

For eg.

Return-Path: <admin@correct.com>
Received: from noc.wrong.com ([76.76.11.105])
by mx.google.com with ESMTP id 42si3780510ywh.71.2009.;
Wed, 11 Nov 2009 22:59:31 -0800 (PST)
Received-SPF: neutral (google.com: .......;
Authentication-Results: mx.google.com; .......
Received: from wronguser by noc.wrong.com with local(Exim 4.69)
(envelope-from <admin@wrong1.com>)ntid 1N8TeT-0007On-F6ntfor jebasingh.emmanuel@gmail.com ; Thu, 12 Nov 2009 01:59:29 -0500

See the envelope-from? That was not being set properly event by using the 5th parameter in php mail as ‘-fadmin@correct.com’

The fix for that was easy, set

trusted_users=domainusername

in /etc/exim.conf.

The trusted_users variable is a colon delimited list of user accounts whose domains should be allowed to send mail as themselves.

Now for the actual code fixes, which can be found here.

General Exim method which doesn’t exactly work as advised. Might need modifications.

WHM specific method.

The problem with the first method was that $interface_address was not set at all for outgoing mail. Since we do not receive incoming mail for our domains, I didn’t get to check how the incoming mails were working out. If you are using WHM, however, you just need to create the files /etc/mailhelo and /etc/mailips and you are good to go after restarting exim. (test with exim -bV first)

I get these headers after the edit.


Return-Path: <admin@correct.com>
Received: from correct.com ([76.76.11.105])
by mx.google.com with ESMTP id 42si3780510ywh.71.2009.;
Wed, 11 Nov 2009 22:59:31 -0800 (PST)
Received-SPF: neutral (google.com: …….;
Authentication-Results: mx.google.com; …….
Received: from correctuser by noc.wrong.com with local(Exim 4.69)
(envelope-from &amp;lt;admin@correct.com&amp;gt;)ntid 1N8TeT-0007On-F6ntfor jebasingh.emmanuel@gmail.com ; Thu, 12 Nov 2009 01:59:29 -0500</pre>

Couldn’t figure out how to set the smtp_active_hostname in exim.conf since $interface_address wasn’t being set. Still, the mails no longer end up in the junk mail folder on gmail, yahoo, aol and hotmail, so I think I am golden.

Took ages to get the above links. Just hope it helps someone else too.

Mysql and Top pruner

The server had a setup in which a cronjob was used to dump output of top command to a directory accessible via http once every 5 minutes. To get rid of the logs and also to prune mysql logs the following script was made.


#! /bin/sh

LOGGER_PATH='/usr/local/apache/htdocs/top/'
N_DAY=3
MYSQL_DATA_DIR='/var/lib/mysql'
LOGSTOKEEP=3

################################################
#find and delete all files
#in logger path older than n days
################################################

find $LOGGER_PATH -mtime +$N_DAY -exec rm -f {} ;

################################################
#mysql pruner section.
#flush logs first,
#find the last filename
#and purge binary logs upto that
################################################

#mysql flush logs here

FILENAMES=`ls $MYSQL_DATA_DIR | grep -e "^mysql-bin.0+[[:digit:]]+$"|sort|tail -n $LOGSTOKEEP`
LINECOUNT=`echo $FILENAMES|wc -w`

#linecount will be lesser than or equal to the number of logs we want to keep

if [ $LINECOUNT -lt $LOGSTOKEEP ]; then
echo "$LOGSTOKEEP files were not found. So no purge is being done."
else
LASTFILENAME=`echo $FILENAMES|cut -d' ' -f 1`
#do purge upto lastfilename
fi
exit

Check if a server is down and email admin

A simple shell cronjob to mail the admin when a particular ip is down.

ping -c 1 192.168.0.99 || echo “ipdown” | mail -s “down” jebasingh.emmanuel@gmail.com

Or a bit more larger version

PINGCOUNT=4
IPADDR="192.168.0.59"

COUNT=`ping -c $PINGCOUNT $IPADDR|grep 'received'|awk -F ',' '{print $2}'|awk '{print $1}'`
if [ $COUNT -eq 0 ]; then
  echo "Ping reported no responses from $IPADDR over $PINGCOUNT pings."|mail -s "Ping Failure" "jebasingh.emmanuel@gmail.com"
fi