Tag Archives: email

Asterisk and esmtp (or sendmail) not sending voicemail emails unless first run manually from console

For the past year to 2 years, I have had this issue where asterisk would not send emails out when voicemails were left. The strange thing was that it only worked when I started asterisk manually from command line but it would not work correctly when run from any startup or boot script. After looking into the problem more deeply did I realize that esmtp does not run as root when called by asterisk unless asterisk was first started by root. The example below is the only way ive found to get asterisk to send emails without killing the application first and starting it manually through the console as a root user every time I rebooted the device.

In your voicemail.conf file use the line below to get asterisk to run esmtp as root even when started by a boot script. Be sure to replace the exact directory location of esmtp/sendmail with yours.

mailcmd=su -c “/opt/bin/esmtp -t -f your@email.com”

You could also replace the command with the sendmail equivalent since esmtp mimics sendmail to a certain degree. The command I listed isnt rocket science, but i just didnt know enough about linux to actually implement it correctly in the voicemail.conf file. Hopefully this helps someone figure out why asterisk will not send emails with the voicemail as an attachment unless run manually via command line and not by a boot script.

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!