[SOLVED] How To Email Call Recordings Post Call Recording Script

Very good, it works great.
Thank you guys.

Hello, guys, thanks a lot for this solution.

Could someone help me with adding call duration into the e-mail body?
I’ve added # $6 - Call duration as a comment and Call duration: $6\n into e-mail body, but I still have no idea what variable to use in Post Call Recording Script. I’ve tried ^{DIALEDTIME} (which gives nothing) and ^{CDR(duration)} (which gives 0 as the result).

Thanks in advance.

Hi, Thanks,
Is there any documentation for variables that i can use ?

If someone who has gotten this to work could post the last few resultant log file lines so others can compare with theirs it would be much appreciated.

Here is mine. The app_mixmonitor.c seems to be ending the recording after executing the email script. Is this normal?

NOTE: I know there are no FREEPBX passed variables; I was testing with a hard-coded email to see what was broken and why my emails aren’t being sent by the script.

UPDATE: The script works as intended when called directly from command line. This leaves only the possibility that the server is preventing the complete execution somehow for some reason. As noted above, file-dependent variables are not factors.

A list from 2016…

Not sure if this is what FREEPBX also uses because {TIMESTR} isn’t mentioned.
Still, if you look at the Asterisk log file you’ll see that variable works.

Finally got this working. Make certain that any email configuration file (.muttrc for instance) is where it is expected to be by the user (in this case asterisk) running the post-call script. In mutt’s case, the file needs to be in ~/ of the asterisk user.

Also, remember variables need to be “$var”, not ‘$var’ in order to pass their values in the echo.

After the above was fixed, call recordings went to my inbox without a hitch!

1 Like

Great thread guys, thanks very much for the script.

I have been struggling to send out HTML emails using this script, can anyone show me how?

I want the HTML to have variables just like this script.


Thanks a lot for sharing this information! - it is eactly what I was looking for.

I tried the first script (just wav, no mp3) and I receive the mail.
It contains all information properly (from, to, time etc.)
but unfortunately no wav attachment.

The mail I receive in my mailclient looks as follows…:


You have a new call recording to listen to

The call date and time was 03/18/2018 07:48:25 PM

The call was from #deleted#

The call was to #deleted#

So no attachment but the path to the wav file in text-form…
What did I miss?

thanks a lot!

Ok i know this is a little old but this request came to me from a customer.

They want to be able to do one touch call record and then for the system to email the recording to them. I was like hmm maybe i can do it but not right now. Sales guy was like “Sure we can do that. Righto Chip Chip Charoo.” That’s how i think my sales guy acts towards customers with no regard to what the system can do just to please the potential customer.

So i found this post and worked on it a bit.

I went through the Asterisk Variables website posted above. and found that what i want to do us use the following in Post Call Recording Script.

/var/lib/asterisk/bin/emailrecording.sh ^{TIMESTR} ^{CALLFILENAME} ^{UNIQUEID} ^{CHANNEL(name)}

Now the following variables are available in my script
$1 is the time of the call
$2 is the filename of the recording
$3 is the unique id of the call
$4 is who the call was with

Now that i had the extension I took advantage of the asterisk db userman_users filed where my username is the extension.

I did a simple sql query:
mysql -u root -e “SELECT email FROM asterisk.userman_users where username = $4”

And as long as you are creating usermanagement users of your extensions and using the extension as the username this will all work for you.

# This script emails the recorded call right after the call is hung up. Below are the variables passed through asterisk
# $1 - Time String
# $2 - File
# $3 - unique id
# $4 - Who is the call with
# $dt - Date and Time

/bin/nice /bin/sleep 3

dy=$(date '+%Y')
dm=$(date '+%m')
dd=$(date '+%d')

/bin/nice /usr/local/bin/lame -b 16 -m m -q 9-resample $dtpath$2.wav  $dtpath$2.mp3
/bin/nice /bin/chown  asterisk:asterisk $dtpath/$2.mp3

dt=$(date '+%m/%d/%Y %r')

echo $dt

# the above exten takes the string of $4 which is the Channel name
# this is key in finding who recorded the call and who the call with 
# Example: SIP/2212-00000100
# the exten =${str:4:4} takes the string str which is the example above
# then looks for the 4th position in string and it starts the extension number after that
# Then it takes the second number 4 and says to grab that number of characters and associate with the 
# variable exten. leaving me with 2212 if your extensions are different then 4 characters only change the 
# second number 4 above to the extension length you have
IFS='-' read -a extensions <<< "${filename}"

if [ ${extensions[1]} == $exten ]

email=$(mysql -u root -e "SELECT email FROM asterisk.userman_users where username = $exten")

       echo -e "You have a new call recording to listen to \n\n
       The call date and time was $dt \n
       The call was with extension: $from \n

       Please see the attached file \n\n" | mail -a $dtpath$2.mp3 -s "New Call Recording" $email

       /bin/nice /usr/bin/find /var/spool/asterisk/monitor/  -type f -mtime +"$file_age" |grep wav | \
              while read I; do
                     /bin/rm  "$I"

Now here is what the email looks like in the end.


I updated the code and output above.

I ran into an issue using $FROMEXTEN in the post call recording script it wouldn’t detect the call recording based off if the call direction was external.

So with a little thinking i decided to try and use the $FILENAME and parse that filename for a 4 digit length(which my extensions) are if yours are different then 4 change that value above.

This works better it detects call recording internal-internal, internal-external, and external-internal. My only trouble now is internal-internal. How can i determine who is the party that wanted the call recorded.

I was looking at asterisk output of mixmon it shows the channel id which is the calling party but i’m not sure if thats the receive or starting party or if it’s who called mixmon. If anyone has any input to that it would be greatly appreciated.

Ok that is all resolved.

I updated the code above in my last update I think this irons out my last issues.

Sorry for updating a ticket from Jan 2015 but i think my contributions to this is awesome. You can dynamically choose who gets the email and it will tell you who the calling party is and only send the vm to the user that called the mixmon recorder.

1 Like

Sorry for grabbing out this old thread:

We want to add the CallerID-Name (by querying Superfecta CID module) in the script.
ChatGPT (:slight_smile:) suggests to parse “modules/superfecta/cli/superfecta.php”,

However, there is neither a CLI path nor a superfecta.php file in our installation (FreePBX 16).

Any ideas?