Tag Archives: alert

How to send an email alert using sendmail from Asterisk 1.4 when a call is made through Ooma

I have been using asterisk in conjunction with my Ooma voip device for some time now. My current configuration allows my family and I to place a call from anywhere there is an internet connection out through my ooma device. My family and extended family travel often and this is a great way to be able to still make local calls for free while being away.

While my family uses this setup, I often wondered the details of the calls made out through my Ooma device. Sure I could log into my.ooma.com or even check the asterisk call logs, but it wasnt as neat/tidy or as automated as I would have liked. I snooped around and discovered that Asterisk can run system commands when they are specified in the extensions.conf file!

I scoured the internet for instructions and realized the lack of a good guide for asterisk 1.4 when using sendmail (this guide should work for msmtp as well), so I thought i would share.

Below is my dialplan for sending an email alert when a call is placed through to my ooma device. This can be placed in any dialplan where you would like an email alert to be made to you, so the possibilities are endless!

Asterisk email alert

While many guides are written for use with the linux mail application which can allow for the subject and body to be specified by the command line, I was using sendmail which does not allow for the subject or body to be specified by command line (except using echo statements in a way which asterisk could not duplicate while running from a dialplan ig. (cat > text | echo xxx ; echo xxx ; | sendmail) etc.). Sendmail needs certain variables to be specified in a file, or by running the application and specifying it while it is running.

I found that asterisk would need to create the file dynamically and add the To:, Subject:, and Body text variables before Asterisk/Sendmail would send the customized email that I wanted sent.

*Note: For this to work, you must have sendmail already configured and able to send emails.

[ooma-out]
;make outgoing calls to ooma pstn
exten => _XXXX.,1,System(echo “To: putdestinationemail@here.com” > /opt/etc/init.d/calls)
exten => _XXXX.,n(done),NoOp()
exten => _XXXX.,n,System(echo “Subject: [PBX]: Outgoing call through Ooma” >> /opt/etc/init.d/calls)
exten => _XXXX.,n(done),NoOp()
exten => _XXXX.,n,System(echo “” >> /opt/etc/init.d/calls)
exten => _XXXX.,n(done),NoOp()
exten => _XXXX.,n,System(echo “User ${CALLERID(NUM)} has made an outgoing call through ooma to phone number ${EXTEN} on ${STRFTIME(%C%m%d%y%H%M)}” >> /opt/etc/init.d/calls)
exten => _XXXX.,n(done),NoOp()
exten => _XXXX.,n,System(sendmail -t -f putsendingemail@here.com < /opt/etc/init.d/calls)
exten => _XXXX.,n(done),NoOp()
exten => _XXXX.,n,Dial(SIP/${EXTEN}@pstn,20)
exten => _XXXX.,n,Hangup
exten => _XXXX.,n,Congestion

exten => _XXXX., is used instead of exten => s,n, because I wanted to have any number larger than 4 digits routed out through ooma, since my internal extensions are 4 digits long.
exten => _XXXX.,n,Dial(SIP/${EXTEN}@pstn,20) is my command to send the call out through ooma.

This configuration makes a file located in /opt/etc/init.d called “calls” containing:

To: putdestinationemail@here.com
Subject: [PBX]: Outgoing call through Ooma
User EXTENTIONCALLING has made an outgoing call through ooma to phone number NUMBERCALLED on DATE

The email is sent to the email specified in “putdestinationemail@here.com” from email address specified in putsendingemail@here.com

This dialplan can be customized to suit any email alert you may need to send when placed into any dialplan in the extensions.conf file, so have fun!