Setting up voicemail in Asterisk

For example, I’ll set up voice mail for SIP number 207.
Voice messages will be sent to the email using Postfix.
How to install it I described in this article – Installing and Configuring Postfix.

For starters, let’s point out the following in the context of SIP 207 (usually in /etc/asterisk/sip.conf):

mailbox=207@voicemailcontext

Next, configure the configuration of voice mail in the file /etc/asterisk/voicemail.conf:

[general]
; Format of audio files
format=wav49|gsm|wav
; From whom to send letters with notifications
serveremail=noreply@example.com
; Whether to attach to an audio file
attach=yes
; The maximum number of messages (standard 100, maximum 9999)
maxmsg=100
; Maximum message time in seconds
maxsecs=120
; Maximum greeting time in seconds
maxgreet=60
; Number of seconds of silence before recording is complete
maxsilence=10
; Threshold sensitivity to silence, the lower the sensitivity, the value from 0 to 256, standard 128
silencethreshold=128
; Maximum number of failed connection attempts
maxlogins=3
; Automatically move the listened messages to the "Old" folder. The default is on.
moveheard=yes
; The encoding of messages, the standard ISO-8859-1, with it my part of the text was displayed incorrectly, so it's better to specify UTF-8
charset=UTF-8
; Skip the line "[PBX]:" from the message header
pbxskip=yes
; The text of the line "From:"
fromstring=VoiceMail
; Letter subject
emailsubject=New voice message ${VM_MSGNUM} in the mailbox ${VM_MAILBOX}
; The contents of the letter
emailbody=Dear ${VM_NAME}:\n\n\tYou received a new voice message in length ${VM_DUR} under the number (number ${VM_MSGNUM})\nin the mailbox ${VM_MAILBOX} from ${VM_CALLERID}, at ${VM_DATE}. \n\t
; Date format
emaildateformat=%A, %d %B %Y в %H:%M:%S
pagerdateformat=%T %D
; Standard program for sending mail
mailcmd=/usr/sbin/sendmail -t

[zonemessages]
ru=Europe/Moscow|'vm-received' q 'digits/at' H 'hours' M 'minutes'
ua=Europe/Kiev|'vm-received' q 'digits/at' H 'hours' M 'minutes'

; We will write the context parameters voicemailcontext, 1111 - voice mail password (you can not specify), Username - user name, test@example.com - which address to send voice messages, after the comma you can specify one more, at the end of the option
[voicemailcontext]
207 => 1111,Username,test@example.com,,attach=yes|tz=ua|delete=yes

By the way, if you do not specify “delete=yes”, when the maxmsg limit is reached, the answering machine will say a greeting, and then the text that the subscriber’s voice box is full and do not save the message, or send it to the email. In this case, you need to call the voicemail number and delete the messages. If “delete=yes” is specified, the messages are not stored on the server, they do not come to the voice mailbox, but only sent to the email, in this case the maxmsg limit does not work and the overflow is not possible.

Now, in the configuration of the dial plan /etc/asterisk/extensions.conf in the main context, add the number by calling to which you can listen to the mail:

exten => 500,1,Log(NOTICE, Dialing out from ${CALLERID(all)} to VoiceMail (500))
exten => 500,n,VoiceMailMain(0${CALLERID(num)}@voicemailcontext,s)
exten => 500,n, Hangup

And add the VoiceMail line to the dialing context of the number 207 (after which, if the number is not answered or not on the network, voice mail will work), for example:

[207]
exten => 207,1,Dial(SIP/207,30)
exten => 207,n,Answer
exten => 207,n,VoiceMail(207@voicemailcontext)

Finally we connect to the Asterisk console, reload the configuration, see the list of voice mailboxes and letters:

asterisk -rvv
sip reload
voicemail reload
dialplan reload
voicemail show users
exit

The recorded messages are stored in the directory /var/spool/asterisk/voicemail/
Sound files are stored in /usr/share/asterisk/sounds

See also:
Sending Asterisk voicemail to multiple emails
Solving the error in Asterisk “File vm-newn does not exist in any format”
How to convert audio files to ulaw, alaw, gsm, g722, etc. for Asterisk

Leave a comment

Leave a Reply