[asterisk-users] Interesting email project.

Jian Gao jian.gao at sjgeophysics.com
Tue May 4 10:57:36 CDT 2010



mike mosier wrote:
>
> Hey all.
>
> My boss asked me to implement the following
>
> When DID 713xxxxxxx is dialed send an email to mmosier at xxx.com 
> <mailto:mmosier at xxx.com>. with the time date and CID included in the 
> email. I know how to code some but am looking for the best way to do this.
>
> Sorry I might have asked this a couple months back. I forgot.
>
> Mmosier
> Houston
>
> Respectfully
> Michael D Mosier
> Ftoc Certified
>

Here is the script I am using for email alert. Form Asterisk dialplan:
exten => h,1,System(/path/to/the/script/emailnotice.sh 
"someone at gmail.com" "${CALLERID(num)}" "${CALLERID(name)}" 
"${DIALSTATUS}" "${VMSTATUS}" "${MYEXTEN}" 
"${STRFTIME(${EPOCH},,%Y/%m/%d %H:%M)}")




==================================================
#!/bin/sh
#Used for email alerting of incoming calls
#$1  email address
#$2  callerid num
#$3  callerid name
#$4  dial status
#$5  vm status
#$6  extension
#$7  datetime

if [ $# != 7 ]
then exit 1
fi

#Store command line args in nice variables
EMAIL=$1
CALLERIDNUM=$2
CALLERIDNAME=$3
DIALSTATUS=$4
VMSTATUS=$5
EXTEN=$6
TIMESTAMP=$7

DEBUG=0         #Set to 0 for standard operation.  1 will log inputs and 
mail commands for debugging.
LOGFILE="/var/log/asterisk/IncomingCalls.log"

SENDMAIL=1      #Set to 1 if you want it to email the alert.  0 is 
useful for debugging.
EMAILCMD="/usr/sbin/sendmail -t"
SUBJECT="Incoming call to ${EXTEN} at ${TIMESTAMP}"

#log mail command
if [ ${DEBUG} -eq 1 ]; then
        echo $1 $2 \"$3\" $4 $5 $6 $7>> ${LOGFILE}
fi

#Check we have an email address if not quit
if [ "${EMAIL}" = "" ]; then
        exit 0
fi

if [ ${DIALSTATUS} = "CANCEL" ]; then
        BODY="Caller - ${CALLERIDNAME} (${CALLERIDNUM}) hung up."

elif [ ${DIALSTATUS} = "ANSWER" ]; then
        BODY="Caller - ${CALLERIDNAME} (${CALLERIDNUM}) was answered by 
${EXTEN}."
else
        BODY="[ ${DIALSTATUS} ] ${CALLERIDNAME} (${CALLERIDNUM}) hung up."
        #check for hangup in vm menu.  ex call went to vm and user hung up
        if [ ${VMSTATUS} = "USEREXIT" ]; then
                BODY="[ ${DIALSTATUS} ] ${CALLERIDNAME} (${CALLERIDNUM}) 
hung up on vm."
        fi
        #check for hangup in vm menu.  ex call went to vm and user hung up
        if [ ${VMSTATUS} = "FAILED" ]; then
                BODY="[ ${DIALSTATUS} ] ${CALLERIDNAME} (${CALLERIDNUM}) 
hung up on vm."
        fi
        #if they left a vm we already would get an email.  Don't need a 2nd
        if [ ${VMSTATUS} = "SUCCESS" ]; then
                exit 0
        fi
fi

#log mail command
if [ ${DEBUG} -eq 1 ]; then
echo "To: ${EMAIL} Subject: ${SUBJECT} ${BODY}" >> ${LOGFILE}
fi

#send email
if [ ${SENDMAIL} -eq 1 ]; then
${EMAILCMD} <<INLINE
From: asterisk at mydomain.com
To: ${EMAIL}
Subject: ${SUBJECT}

${BODY}


INLINE
fi

exit 0


-- 
Jian Gao
IT Technician
SJ Geophysics Ltd. <http://www.sjgeophysics.com>
jian.gao at sjgeophysics.com <mailto:jian.gao at sjgeophysics.com>
Tel: (604)582-1100



More information about the asterisk-users mailing list