Sipdroid's Blog

config voicemail in asterisk

Posted in asterisk by sipdroid on January 18, 2010

1) Config exim4

http://www.manu-j.com/blog/wordpress-exim4-ubuntu-gmail-smtp/75/

2) Config asterisk

http://rblondon.blogspot.com/2008/02/asterisk-voicemail-quick-exim4-notes.html

I don’t see a need to define ( mailcmd=/usr/exim/bin/exim –t )

Asterisk Voicemail – Quick Exim4 notes

After installing asterisk I set up the voicemail configuration. First un apt-get install exim4 and then run pkg-reconfigure exim4-config and follow the instructions.
After the configuration exim4 should restart itself but if not use /etc/init.d/exim4 restart.
Configure the voicemail.conf file as follows:
[general]
format=wav
serveremail=asterisk
attach=yes
skipms=3000
maxsilence=10
silencethreshold=128
maxlogins=3
pbxskip=yes
fromstring=Voicemail
emailbody=Dear ${VM_NAME}:\n\n\tjust wanted to let you know you were just left a ${VM_DUR} long message (number ${VM_MSGNUM})\nin mailbox ${VM_MAILBOX} from ${VM_CALLERID}, on ${VM_DATE}. The message is attached. Thanks!\n\n\t\t\t\t\n
emaildateformat=%A, %B %d, %Y at %r
sendvoicemail=no
delete=yes
[zonemessages]
eastern=America/New_York|’vm-received’ Q ‘digits/at’ IMp
central=America/Chicago|’vm-received’ Q ‘digits/at’ IMp
central24=America/Chicago|’vm-received’ q ‘digits/at’ H N ‘hours’
military=Zulu|’vm-received’ q ‘digits/at’ H N ‘hours’ ‘phonetic/z_p’
european=Europe/Copenhagen|’vm-received’ a d b ‘digits/at’ HM
[default]
89300 => 89300,User1,user1@mailserver.com
Now on Sip.con add the mailbox line (mailbox account and context of voicemail.conf)
[89300]
type=friend
regexten=89300
context=default
mailbox=89300@default
secret=89300
username=89300
callerid=”User1″ <89300>
host=dynamic
nat=yes
canreinvite=no
disallow=all
allow=alaw
allow=ulaw
dtmfmode=inband
Finally on extensions.conf set each SIP extensions (will use macros later) to wait for 20 seconds and go to Voicemails as follows:
[default]
exten => 89300,1,Dial(SIP/89300,20)
exten => 89300,2,VoiceMail(89300@default)
exten => 89300,3,PlayBack(vm-goodbye)
exten => 89300,4,HangUp()

3) Multiple recipients

http://www.voip-info.org/wiki/index.php?page=Asterisk+config+voicemail.conf

– sudo vim /etc/mail/aliases

– Example from voicemail.com: 1234 => 1234,Sample User,msmith,,attach=yes

–  Example from /etc/mail/aliases: msmith: <msmith@yourmail.com>, msmith@othermail.com

– sudo newaliases

4) More flexible script approach

http://tonylandis.com/uncategorized/asterisk-voicemail-sending-emailing-custom/

#!/usr/bin/php -q
<?php
/**
 * ASTERISK PBX VOICEMAIL MAILER
 *
 * @author Tony Landis
 * @link http://www.tonylandis.com
 * @license Use how you like it, just please don't remove or alter this PHPDoc
 */

#
# config smtp info
#
$mail_lib_path  = "/var/www/inc/phpmailer/";	// path to the phpmailer library
$ast_vm_path	= "/var/spool/asterisk/voicemail/default/{MAILBOX}/INBOX/"; // where asterisk mailboxes are located
$ast_vm_ext	= "wav";	// voicemail recording file extensions to look for
$from		= "asterisk-pbx@domain.com";	// from e-mail address to use
$fromName	= "Asterisk PBX Voicemail";	// from name to use when sending email
$host           = "mail.domainn.com";	// smtp host
$username       = ""; // smtp username
$password       = "";	// smtp password
$port 		= "25";	// smtp port

#
# a few php settings
#
error_reporting(0);
set_time_limit(30);

#
# get args from STDIN
#
$args = array();
for($i=0; $i<5; $i++) add2array(trim(fgets(STDIN)), $args); 

#
# parse out the recipient info
#
if(preg_match('/^\"([a-zA-Z0 ]{1,})\" \<(.+)\>/', $args['To'], $matches)) {
	$toEmail = $matches[2]; # to email
	$toName = $matches[1];	# to name
}

#
# Parse the contents of the subject
#
$subject = explode("|", $args['Subject']);
$mailbox = $subject[0];
$msgnum  = $subject[1];
$callerid= $subject[2];
$duration= $subject[3];

#
# compose the email subject and body
#
$subject = "New voicemail for " . ucfirst($toName);
$body    = "Hello " . ucfirst($toName) . ",\r\n" .
		   "You have a new message in for mailbox # {$mailbox} from {$callerid}, with a duration of {$duration}";

#
# mail class
#
require($mail_lib_path . "class.phpmailer.php");
$mail = new PHPMailer();
$mail->Subject  = $subject;
$mail->Body	= $body;
$mail->AddAddress($toEmail, $toName);
$mail->From     = $from;
$mail->FromName = $fromName;
$mail->Host     = $host;
$mail->Mailer   = "smtp";
$mail->SMTPAuth = true;
$mail->Username = $username;
$mail->Password = $password;
$mail->Port 	= $port; 

#
# attempt to attach the voicemail recording
#
if(!empty($mailbox) && !empty($msgnum))
{
	for($i=0; $i<=(5-strlen($msgnum)); $i++) $msgnum = "0" . $msgnum;
	$attach = str_replace("{MAILBOX}", $mailbox, $ast_vm_path) . "msg" . $msgnum . "." . $ast_vm_ext;
	#$mail->Body .= "\r\n" . $attach; # uncomment to debug if messages are not attached
	if(is_file($attach))
		$mail->AddAttachment($attach, "Message-". $mailbox ."-". $msgnum .".". $ast_vm_ext);
}

#
# send the email
#
if($mail->Send())
{
	echo "\r\nSent Ok! \r\n";
} else {
	echo "\r\nSend Failed... \r\n";
	echo $mail->ErrorInfo;
}

#
# function add to the args array
#
function add2array($str, &$args)
{
	if(preg_match("/^([a-zA-Z0-9]{1,}): (.+)/", $str, $matches))
	{
		$key = $matches[1];
		$val = $matches[2];
		$args[$key] = $val;
	}
}

5) Voice as mp3 file

http://www.voip-info.org/wiki/view/Asterisk+Voicemail

– voicemail.conf

mailcmd=perl /var/lib/asterisk/agi-bin/mp3vm.pl

– mp3vm.pl

#!/usr/bin/perl

open(VOICEMAIL,”|/usr/sbin/exim -t”);

open(LAMEDEC,”|/usr/bin/dos2unix|/usr/bin/base64 -di|/usr/bin/lame –quiet –preset voice – /var/spool/asterisk/tmp/vmout.$$.mp3″);

open(VM,”>/var/spool/asterisk/tmp/vmout.debug.txt”);

my $inaudio = 0;

loop: while(<>){                        # read from STDIN that is passed from asterisk

if(/^\.$/){                               #process line G that marks the end of email

last loop;

}

if(/^Content-Type: audio\/x-wav/i){
$inaudio = 1;

}

if($inaudio){

while(s/^(Content-.*)wav(.*)$/$1mp3$2/gi){}     # process  line A-D

if(/^\n$/){                                             # process line E that marks the beginning of wav encoded content

iloop: while(<>){                                  # process line with wav encoded content and convert to mp3

print LAMEDEC $_;

if(/^\n$/){                                         #process line F that marks the end of wav encoded content

last iloop;

}

}

close(LAMEDEC);

print VOICEMAIL “\n”;

print VM “\n”;

open(B64,”/usr/bin/base64 /var/spool/asterisk/tmp/vmout.$$.mp3|”);  # $$ stands for process id

while(<B64>){

print VOICEMAIL $_;                       #  dump the while mp3 file
print VM $_;

}

close(B64);

print VOICEMAIL “\n”;

print VM “\n”;

$inaudio = 0;

}

}                                                    # match the if ($inaudio)

print VOICEMAIL $_;                      # process lines that are not wav encoded related.

print VM $_;

}

print VOICEMAIL “\.”;

print VM “\.”;

close(VOICEMAIL);

close(VM);

#CLEAN UP THE TEMP FILES CREATED

#This has to be done in a separate cron type job

#because unlinking at the end of this script is too fast,

#the message has not even gotten piped to send mail yet

sample file:

Date: Mon, 18 Jan 2010 15:01:02 -0800

From: “Voicemail” asterisk@home

To: “Mr XYZ” <homenotify>

Subject: New message 2 in mailbox 2009

Message-ID: <Asterisk-2-1800285858-2009-6826@m9000t>

MIME-Version: 1.0

Content-Type: multipart/mixed; boundary=”—-voicemail_2200968261038445079″

This is a multi-part message in MIME format.

——voicemail_2200968261038445079

Content-Type: text/plain; charset=ISO-8859-1

Content-Transfer-Encoding: 8bit

Dear Mr XYZ:

just wanted to let you know you were just left a 0:23 long message (number 2)

in mailbox 2009 from an unknown caller, on Monday, January 18, 2010 at 03:01:02 PM. The message is attached. Thanks!

——voicemail_2200968261038445079

Content-Type: audio/x-mp3; name=”msg0002.mp3″                                <—– line A
Content-Transfer-Encoding: base64

Content-Description: Voicemail sound attachment.

Content-Disposition: attachment; filename=”msg0002.mp3″                  <—-  line  D

<—- line E there is a \n

/+NIxAAAAAAAAAAAAFhpbmcAAAAPAAABRQACZSAAAwUHCg0PEhQXGhweISQmKCsuMDI2ODo9QEJF

R0………………….

…….

xnCmRrWzAqJRmKkhr24QhFQzTTA19b4RBwZfpYbFutHIam45DVDJIaoY5DVDBlVMQU1FMy45N1VV

VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV/+MYxCIAAANIAcAAAFVVVVVVVVVVVVVVVVVVVVVVVVVV

VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV

<—–line F there is a \n

——voicemail_2200968261038445079–

.                                           <——line G this is the end of e-mail

as you can see, it is very easy to manipulate the file and add Bcc or CC

more perl tutorial: http://aplawrence.com/Unix/perlinput.html

6) voice to text

There are companies that sell such a service

http://www.phonewire.com/cc/voicemail?=/

http://www.tellme.com/business

http://www.spinvox.com/how_it_works.html http://forge.asterisk.org/gf/project/spintools/

http://www.phonetag.com/

7) Receive Fax and send as e-mail attachment

in extensions.conf

[macro-faxreceive]
exten => s,1,Set(FAXFILE=/var/spool/asterisk/tmp/${UNIQUEID}.tif)
exten => s,2,Set(EMAILADDR=abcdefg@gmail.com)
exten => s,3,rxfax(${FAXFILE})

[fax]
exten => 2222,1,Macro(faxreceive)
exten => h,1,system(/var/lib/asterisk/agi-bin/mailfax ${FAXFILE} ${EMAILADDR} “${CALLERIDNUM} ${CALLERIDNAME}”)

[default]

; Did we get a fax?
exten => fax,1,Goto(fax,2222,1)

and you have the file /var/lib/asterisk/agi-bin/mailfax

#!/bin/sh

FAXFILE=$1
RECIPIENT=$2
FAXSENDER=$3

#tiff2ps -2eaz -w 8.5 -h 11 $FAXFILE | ps2pdf – | uuencode fax.pdf | mail -s “Fax sent from $FAXSENDER” $RECIPIENT
tiff2ps -2eaz -w 8.5 -h 11 $FAXFILE | ps2pdf – | mime-construct –to $RECIPIENT –subject “Fax from $FAXSENDER” –attachment fax.pdf –type application/pdf –file –

8)  Send fax  not implemented yet.

Advertisements