I have been very disappointed with the voicemail emailing capabilities of Asterisk PBX. If you need to use a SMTP host, it can be a time consuming task to configure sendmail, postfix, etc, to use an external SMTP provider. And once you get the emails to send, customizing and scripting is very limited.
I wanted to be able to use SMTP, add BCC and CC recipients, have full scripting control over the message body and subject, and attach the voicemail recording in the e-mail. It seemed like writing a script and using the ‘mailcmd’ setting in the [general] section of the asterisk voicemail.conf file was a suitable way to handle this, so I took this route.
First, my asterisk voicemail.conf entries (the mailcmd, emailsubject, and format settings must be adhered to):
[general]
maxsilence=6
maxmessage=360
minmessage=4
delete=no
mailcmd=/var/www/voicemail-send.php
emailsubject=${VM_MAILBOX}|${VM_MSGNUM}|${VM_CALLERID}|${VM_DUR}
format=wav
[default]
100 => 101010,Tony,my@email.com
Then I dropped the PHP script below into my /var/www/ directory with a name of voicemail-send.php and ran chown asterisk:asterisk on it to be sure asterisk can execute. You will need to download the phpmailer library and set the $mail_lib_path variable with the path to that library, as well as make sure the $ast_vm_path is correct. The email/smtp variables will also need to be set with your correct information.
That is all… Asterisk will now call voicemail-send.php after each voicemail is saved and if everything is configured correctly as described above, the voicemail email alert and attachment will be sent to the email address for the mailbox configured in the asterisk voicemail.conf file.
You can run the voicemail-send.php script from the command line and enter these lines (then press return about 4 times) to test without actually placing calls, where your@email.com is a real email address and 195 is a real mailbox and 1 a real msg000NUM.wav file to be attached:
To: "Test User" <your@email.com> Subject: 100|1|8881234567|12:22
Thanks a lot, this is a nice way to send a mail outside the LAN with Asterisk. I dont know much of PHP but the code is transparent.
Greetings From Mexico
I was having problems setting up my Trixbox PBX (Asterisk-based) as it wouldn’t e-mail notifications for voicemails. Found out the problem was that my ISP blocked Port 25 and I had to use their SMTP as relay server.
Wish I found this script prior
Thanks!
I have problem using:
mailcmd=/var/www/voicemail-send.php
So, I tried to change it to:
mailcmd=/var/www/voicemail-send.php
And it’s working well.. I don’t know what could be the reason behind that..
Anyway, thanks so much. This is a very great article!!!
I have problem using:
mailcmd=/var/www/voicemail-send.php
So, I tried to change it to:
mailcmd=php /var/www/voicemail-send.php
And it’s working well.. I don’t know what could be the reason behind that..
Anyway, thanks so much. This is a very great article!!!
I have problem:
I got email without attached voice file :
Hello Gamal Hammad,
You have a new message in for mailbox # =?ISO-8859-1?Q?101 from =22Hazem_Gamal=22_=3C1007=3E, with a duration of 0=3A03?=
it seem that the variables come with wrong data.
how can I go around that. I use asteriskNOW and I download and work with it just two week ago.
and here is my voicemail.conf
[general]
#include vm_general.inc
maxsilence=6
maxmessage=360
minmessage=4
delete=no
mailcmd=php /var/www/voicemail-send.php
emailsubject=${VM_MAILBOX}|${VM_MSGNUM}|${VM_CALLERID}|${VM_DUR}
format=wav
[default]
101 => 123456,Gamal Hammad,gamal@ezz-elarab.com
thanks
Dear Tony ,
I would really appreciate your help to know how can I do the following to your secipt :
1. Convert waf file and send a mp3 ( found a perl file to do that bout would like to use ur script for smtp instead http://trixbox.org/forums/trixbox-forums/trixbox-projects/emailing-voicemail-messages-mp3-files#comment-160936 )
2.Is there a way I can pass user email id from agi as I dont plan to make users in voicemail.conf would would only make one default user . so I would like to some how pass the email address where the voicemail should go from the dialplan using aig & php . so would like to know how can I pass it to your file as mailcmd=/var/www/voicemail-send.php is predefined and hardcode in the voicemail.conf . Is it possible to do some thing like this mailcmd=/var/www/voicemail-send.php?toEmail=$value , as the $value will be passed by dialplan . what I cant figure is that how will I pass the email address from dialplan .