[SOLVED] Get voicemail message programatically (PHP)

Hey all, does anyone know how to grab a voicemail message file name based on the mailbox ID so it can be emailed as an attachment? I know Asterisk can natively email a voicemail as an attachment, but it is limited to a fixed email address in the config. In my situation there will be different users (email addresses) that would need to be emailed based on time of day/day of week depending on the contacts availability setting, so a fixed email address won’t work. A “shared” email box (forwarding group) also wont work for the same reasons. Contacts may be added/removed at any time, and unavailable contacts won’t want to receive emails. Anyone have any ideas how how this might be able to be done with an AGI script (maybe PHP) by passing it the mailbox ID and then returning the file name of the message back so it can then be used in a variable to add to the email as an attachment? TIA to all for any ideas!


You need to parar the STDIN output from asterisk. Something like this: asterisktools.blogspot.mx/2012/1 … ra-el.html

Thanks for the info navaismo! Unfortunately, it’s not quite what I need. I can’t make changes to the voicemail.conf for the email settings, as some extensions already utilize the “normal” emailing of messages to an extensions email address. I can already send an email from a separate AGI I’m calling, what I actually need is to be able to attach the new voicemail to the email being sent. The problem is getting the name of the voicemail file and attaching it in the message. The email AGI can already send the email with an attachment if wanted, I just don’t know how to get the name of the message file left so it CAN be attached to the existing email. I need to be able to somehow get the name of the message file based on the mailbox ID from a separate AGI (an example would be to use a PHP script to look at the INBOX of say mailbox 1000, see there is a new message, then return the directory and name of the message file so it can be attached to the outgoing email) but I’m not sure how to accomplish this. :unamused:


The VoiceMail Channel Variables could help you. I think in your case is ${VM_MESSAGEFILE}

${VM_CATEGORY} - Sets voicemail category
${VM_NAME} * - Full name in voicemail
${VM_DUR} * - Voicemail duration
${VM_MSGNUM} * - Number of voicemail message in mailbox
${VM_CALLERID} * - Voicemail Caller ID (Person leaving vm)
${VM_CIDNAME} * - Voicemail Caller ID Name
${VM_CIDNUM} * - Voicemail Caller ID Number
${VM_DATE} * - Voicemail Date
${VM_MESSAGEFILE} * - Path to message left by caller

Thanks ambiorixg12, I’ll take a look and see what info I can grab from them.


Kevin you can write a PHP script that add the file name of every message to MYSQL DB using the variable ${VM_MESSAGEFILE} and a column in the db called new, then another script that query the db periodically or after the execution of the first script, and if message has the status of new in the DB this last script will send the email with vms attached using the value of the var ${VM_MESSAGEFILE}

Can someone tell me where/when the ${VM_MESSAGEFILE} variable is set? When I do a NoOP with the variable it always returns empty. When a voicemail is left I’m running a shell script for externnotify, which reads the mailbox number and number of new messages, and that script calls a PHP script and passes those variables to the PHP script, which creates a callfile to call my subroutine in the form of LOCAL/s@myroutine. I’m not sure where I need to grab this variable from. It’s not showing up in myroutine, and from what I’ve read, externnotify doesn’t pass that variable to the script it calls, so I’m not quite sure how I can get the proper filename for the mailbox number I’m passing to my script. :frowning: Anyone have an ideas? Thanks!


NoOp this variable after using Voicemail() in your dialplan and paste the CLI output.

–Satish Barot

Hey all, I actually solved this by using a PHP AGI script that I pass the voice mailbox number to and it searches that directory for the newest wav file based on date and time and then returns the filename in a variable which I then use for my purposes. Thanks to all who responded!