Just leave a message, maybe I’ll call.
Joe Walsh
Before email and instant messaging became ubiquitous, voicemail was a popular method of electronic messaging. Even though most people now prefer text-based messaging systems, voicemail remains an essential component of any PBX.
Asterisk has a reasonably flexible voicemail system named Comedian Mail.1 Voicemail in Asterisk is provided in the dialplan by the
app_voicemail.so
module.
Some of the features of Asterisk’s voicemail system include:
Unlimited password-protected voicemail boxes, each containing mailbox sub-folders for organizing voicemail
Different greetings for busy and unavailable states
Default and custom greetings
The ability to associate phones with more than one mailbox, and mailboxes with more than one phone
Email notification of voicemail, with the voicemail optionally attached as an audio file
Voicemail forwarding and broadcasts
Message-waiting indicator (flashing light or stuttered dialtone) on many types of phones
Company directory of employees, based on voicemail boxes
We’re now going to take you on a tour of the essential parts of the voicemail configuration file, covering the settings in the general section, the various regional settings that are possible, integration of voicemail into your dialplan, and a brief under-the-hood look at how Asterisk stores voicemail in the Linux filesystem.
Since we’ve installed the table required for voicemail in the MySQL database, it is possible to create mailboxes there without any other configuration. It is, however, also possible to create mailboxes in an /etc/asterisk/voicemail.conf file (this file also allows you to change various other default settings). We’ll continue to use the database to create and manage users, since it is far more suited to the task, but we’ll also explore the configuration file so that you can get a sense of the flexibility possible with Asterisk’s voicemail.
The voicemail.conf file contains several sections where various default parameters can be adjusted. For the most part, you won’t need to change any of these; however, you should take a look at the ~/src/asterisk-1.15.<your version>/configs/samples/voicemail.conf.sample file. It contains useful information about various options that can be adjusted.
We have provided a simple voicemail.conf file next. If you wish to tweak the basic configuration beyond this, simply add or edit the relevant option.
We recommend the following sample as a starting point. You can refer to ~/asterisk-complete/asterisk/11/configs/voicemail.conf.sample for details on the various settings.
Place the following in a file named /etc/asterisk/voicemail.conf:
; Voicemail Configuration [general] format=wav49|wav [email protected] attach=yes skipms=3000 maxsilence=10 silencethreshold=128 maxlogins=3 emaildateformat=%A, %B %d, %Y at %r pagerdateformat=%A, %B %d, %Y at %r sendvoicemail=yes ; Allow the user to compose and send a voicemail while inside [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
Setting up a Linux server to handle the sending of email is a Linux administration task that is beyond the scope of this book. You will need to test your voicemail-to-email service to ensure that the email is being handled appropriately by the Mail Transfer Agent (MTA),2 and that downstream spam filters are not rejecting the messages (one reason this might happen is if your Asterisk server is using a hostname in the email body that does not in fact resolve to it).
You can create a massive and complex voicemail.conf file (and can even store user mailboxes in it), but we’re going to focus on a few curated examples to keep things simple. You’ll likely find that what we present will serve your needs quite well (and that the documentation samples will provide more detail, should you require it).
The first section of the voicemail.conf file, [general]
, allows you to define global
settings. Many of these settings can be assigned on a per-mailbox
setting. We’ve listed in Table 8-1 a few
settings that we feel are the most important to consider.
Option | Value/example | Notes |
---|---|---|
format | | For each format listed, Asterisk creates a separate recording in that format whenever a message is left. The benefit is that some transcoding steps may be saved if the stored format is the same as the codec used on the channel. We like WAV because it is the highest quality, and WAV49 because it is nicely compressed and easy to email. We don’t like GSM due to its scratchy sound, but it enjoys some popularity.a |
serveremail | user@domain | When an email is sent from Asterisk, this is the email address that it will appear to come from.b |
attach | yes,no | If an email address is specified for a mailbox, this determines whether the message is attached to the email (if not, a simple message notification is sent, and the user will need to call into voicemail to retrieve their messages). |
maxmsg | 9999 | By default, Asterisk only allows a maximum of 100 messages to be stored per user. For users who delete messages, this is no problem. For people who like to save their messages, this space can get eaten up quickly. With the size of hard drives these days, you could easily store thousands of messages for each user, so our current thinking is to set this to the maximum and let the users manage things from there. Be aware that old voicemail messages on a large system can waste a lot of hard drive space, after a few years of storing every message. |
maxsecs | 600 | This type of setting was useful back when a large
voicemail system might have only 40 MBc of storage: it was necessary to limit the system
because it was easy to fill up the hard drive. This setting can
be annoying to callers (although it does force them to get to
the point, so some people like it). Nowadays, with terabyte
drives common, there is no technical reason to limit the length
of a message. Two considerations are: 1) if a channel gets hung
in a mailbox, it’s good to set some sort of value so it doesn’t
mindlessly record an endless, empty voice message, but 2) if a
user wants to use her mailbox to record notes to herself, she
won’t appreciate it if you cut her off after 3 minutes. A
setting somewhere between 600
seconds (10 minutes) and 3600
seconds (1 hour) will probably be about right. |
emailsubject | [PBX]: New message ${VM_MSGNUM} in mailbox ${VM_MAILBOX} | When Asterisk sends an email, you can use this setting to
define what the Subject: line
of the email will look like. See the voicemail.conf.sample file for more
details. |
emailbody | Dear ${VM_NAME}:
you have a ${VM_DUR} long message (number ${VM_MSGNUM})
in mailbox ${VM_MAILBOX}
--Asterisk
| When Asterisk sends an email, you can use this setting to define what the body of the email will look like. See the voicemail.conf.sample file for more details. |
emaildateformat | %A, %d %B %Y at %H:%M:%S | This option allows you to specify the date format in
emails. Uses the same rules as the C function STRFTIME . |
pollmailboxes | no, yes | If the contents of mailboxes are changed by anything
other than app_voicemail
(such as external applications or another Asterisk system),
setting this to yes will
cause app_voicemail to poll
all the mailboxes for changes, which will trigger proper message
waiting indication (MWI) updates. |
pollfreq | 30 | Used in concert with pollmailboxes , this option specifies
the number of seconds to wait between mailbox polls. |
a The separator that is used for
each format option must be the pipe ( b Sending email from Asterisk can require some careful configuration, because many spam filters will find Asterisk messages suspicious and will simply ignore them. We talk more about how to set email for Asterisk in “Voicemail to Email”. c Yes, you read that correctly: megabytes. |
Part of the [general]
section is an area of supplementary
options (referred to in the config file as advanced
options, though there’s not really anything advanced about
them). These options (listed in Table 8-2)
are defined in the same way as the other options in the [general]
section, but what is significant
about them is that they can also be defined on a per-mailbox basis,
which would override whatever is defined under [general]
for that particular
setting. In other words, the following options can be set in
the database when you create a new mailbox.
Option | Value/example | Notes |
---|---|---|
tz | eastern , european , etc. | Specifies the zonemessages name, as defined under
[zone messages] (discussed in the next
section). |
locale | de_DE.utf8 , es_US.utf8 , etc. | Used to define how Asterisk generates date/time strings
in different locales. To determine the locales that are valid on
your Linux system, type locale -a at the
shell. |
attach | yes , no | If an email address is specified for a mailbox, this determines whether the messages are attached to the email notifications (otherwise, a simple message notification is sent). |
attachfmt | wav49 , wav , etc. | If attach is enabled
and messages are stored in different formats, this defines which
format is sent with the email notifications. Often wav49 is a good choice, as it uses a
better compression algorithm and thus will use less bandwidth,
but doesn’t sound crappy, as gsm does. |
exitcontext | context
| There are options that allow the callers to exit the voicemail system when they are in the process of leaving a message (for example, pressing 0 to get an operator). By default, the context the caller came from will be used as the exit context. If desired, this setting will define a different context for callers exiting the voicemail system. |
review | yes , no | This should almost always be set to yes (even though it defaults to
no ). People get upset if your
voicemail system does not allow them to review their messages
prior to delivering them. |
operator | yes , no | Best practice dictates that you should allow your callers
to “zero out” from a mailbox, should they not wish to leave a
message. Note that an o
extension (not “zero,” but “oh”) is required in the exitcontext in order to handle these
calls. |
delete | no , yes | After an email message notification is sent (which could
include the message itself), the message will be deleted. This
option is risky, because the fact that a message was emailed is
not a guarantee that it was received (spam filters seem to love
to delete Asterisk voicemail messages). On a new system, leave
this at no until you are
certain that no messages are being lost due to spam
filters. |
nextaftercmd | yes , no | This handy little setting will save you some time, as it takes you directly to the next message once you’ve finished dealing with the current message. |
passwordlocation | spooldir | If you want, you can have mailbox passwords stored in the
spool folder for each mailbox.a One of the advantages of using the spooldir option is that it will allow
you to define file #include
statements in voicemail.conf (meaning you can store
mailbox references in multiple files, as you can with, for
example, dialplan code). This is not possible otherwise, because
normally
writes password changes to the filesystem, and cannot update a
mailbox password stored outside of either voicemail.conf or the spool. If you
do not use passwordlocation ,
you will not be able to define mailboxes outside of voicemail.conf, since password
updates will not happen. Storing passwords in a file in the
specific mailbox folder in the spool solves this
problem. |
a Typically the spool folder is /var/spool/asterisk, and it can be defined in /etc/asterisk/asterisk.conf. |
The next section of the voicemail.conf file is the [zonemessages]
section. The purpose of this
section is to allow time zone–specific handling of messages, so you can play back to the user messages with the
correct timestamps. You can set the name of the zone to whatever you
need. Following the zone name, you can define which time zone you want
the name to refer to, as well as some options that define how timestamps
are played back. You can look at the ~//src/asterisk-16.<TAB>/configs/samples/voicemail.conf.sample
file for syntax details. Asterisk includes the examples shown in Table 8-3. Any valid time zone known to the Linux
system should be configurable.
Just use the Linux name for the zone, and then provide the details of
how you want it handled.
Zone name | Value/example | Notes |
---|---|---|
eastern | America/New_York|'vm-received'
Q 'digits /at' IMp | This value would be suitable for the Eastern time zone (EST/EDT). |
central | America/Chicago|'vm-received' Q
'digits/at' IMp | This value would be suitable for the Central time zone (CST/CDT). |
central24 | America/Chicago|'vm-received' q
'digits/at' H N 'hours' | This value would also be suitable for CST/CDT, but would play back the time in 24-hour format. |
military | Zulu|'vm-received' q 'digits/at'
H N 'hours'
'phonetic/z_p' | This value would be suitable for Universal Time Coordinated (Zulu time, formerly GMT). |
european | Europe/Copenhagen|'vm-received'
a d b 'digits/at' HM | This value would be suitable for Central European time (CEST). |
You can configure mailboxes in the voicemail.conf file, but it’s not the recommended way. We’re going to use the database to define your mailboxes.
The first thing we need to do is tell Asterisk that voicemail users are available in the database. We do that by editing the /etc/asterisk/extconfig.conf file:
$ sudo vim /etc/asterisk/extconfig.conf [settings] ; older mechanism for connecting all other modules to the database ps_endpoints => odbc,asterisk ps_auths => odbc,asterisk ps_aors => odbc,asterisk ps_domain_aliases => odbc,asterisk ps_endpoint_id_ips => odbc,asterisk ps_contacts => odbc,asterisk voicemail => odbc,asterisk,voicemail
You
should restart Asterisk to ensure this change has been applied
($ sudo service asterisk restart
).
In the voicemail system, a mailbox must be defined with a context.
This does not relate to any dialplan context; it’s a label specific to
voicemail that will determine what mailboxes will be grouped together,
and is also used to name the folder in the spool that contains the
various files associated with this mailbox (greeting, messages,
envelopes, and so forth). Normally, you don’t need to worry about this,
as all mailboxes will end up in the default
context. You really only need to
define various contexts if you have a complex, multi-tenanted system,
where there’s a potential for extension overlap, or where you don’t want
certain groups of users exposed to other groups of users.
The `asterisk`.`voicemail`
table offers many options; however, to create a mailbox there are only
three fields that are required, plus two more that are recommended. The
context
, mailbox
, and password
fields are required, and fullname
and email
are strongly recommended. Here’s a
simple MySQL INSERT
that’ll create some mailboxes for
you.
INSERT INTO `asterisk`.`voicemail` (context,mailbox,password,fullname,email) VALUES ('default','100','486541','Russell Bryant', '[email protected]'), ('default','101','957642','Leif Madsen', '[email protected]'), ('default','102','656844','Jared Smith', '[email protected]'), ('default','103','375416','Jim VanMeggelen', '[email protected]') ;
The parts of the mailbox definition are:
mailbox
This is the mailbox number. It is normal to ensure it corresponds with the extension number of the associated set.
password
This is the numeric password that the mailbox owner will use to access her voicemail. If the user changes her password, the system will update this field in the database.
If the password is preceded by the hyphen (-) character, the user cannot change their mailbox password.
fullname (FirstName
LastName)
This is the name of the mailbox
owner. The company directory uses the text in this field to allow
callers to spell usernames. You only get one space, which is meant
to delimit the first name from the last name, so if your last name
is something like Van Meggelen, you’ll put
that in as VanMeggelen
. Other
punctuation characters might also cause problems. (We’re looking
at you, O’Reilly.)
email address
This is the email address of the mailbox owner. Asterisk can send the voicemail to the specified email box.
The Asterisk directory cannot handle the concept of a surname that is anything other than a simple word. This means that family names such as O’Reilly, Bryant-Madsen-Smith, and yes, even Van Meggelen must have any punctuation characters and spaces removed before being added to voicemail.conf.
There are quite a few other options you can define for each user. It’s unlikely you’ll use many of them, but Table 8-4 contains a curated list of some that may be of use to you.
Option | Description |
---|---|
delete | After Asterisk sends the voicemail via email, the
voicemail is deleted from the server. This option is useful for
users who only want to receive voicemail via email. Valid
options are yes or no . Option can only be set
per mailbox. |
envelope | Turns on or off envelope playback prior to playback of
the voicemail message. Valid options are yes or no . Default is yes . |
exitcontext | The dialplan context to exit to when pressing * or 0 from
the Voicemail() application.
Works in conjunction with the operator option as well. Must have an
extension a in the context
for exiting with *. Must have an extension o in the context for exiting with 0.
You’ll need to do a bit of design work before your dialplan will
be able to handle this well, so it’s best to leave it blank
until you’ve had a chance to prototype everything you’ll need to
handle. |
forcegreeting | Forces the recording of a greeting for new mailboxes. A
new mailbox is determined by the mailbox number and password
matching. Valid values are yes or no . Default is no . |
forcename | Forces the recording of the person’s name for new
mailboxes. A new mailbox is determined by the mailbox number and
password matching. Valid values are yes or no . Default is no . |
hidefromdir | If set to yes , this
mailbox will be hidden from the Directory() application. Default is
no . |
locale | Allows you to set the locale for the mailbox in order to control formatting of the date/time strings. See voicemail.sample.conf for more information. |
messagewrap | Allows the first and last messages to wrap around (e.g.,
allow last message to wrap back to the first on the next
message, or first message to wrap to the last message when going
to the previous message). Valid options are yes or no . Default is no . |
minpassword | Sets the minimum password length. Argument should be a whole number. |
nextaftercmd | Skips to the next message after the user presses the 7
key (delete) or 9 key (save). Valid values are yes or no . Default is yes . |
operator | Will allow the sender of a voicemail to hit 0 before,
during, or after recording of a voicemail. Will exit to the
o extension in the same
context, or the context defined by the exitcontext option. Valid options are
yes or no . Default is no . There are security risks
associated with this, so it’s best not to use it until you’re
certain the exitcontext does not allow calls
to leave the system (i.e., end up making an expensive overseas
call). |
passwordlocation | By default, the password for voicemail is stored in the
voicemail.conf file, and
modified by Asterisk whenever the password changes. This may not
be desirable, especially if you want to parse the password from
an external location (or script). The alternate option for
passwordlocation is spooldir , which will place the
password for the voicemail user in a file called secret.conf in the user’s voicemail
spool directory. Valid options are voicemail.conf and spooldir . The default option is
voicemail.conf . |
review | When enabled, will allow the user recording a voicemail
message to re-record their message. After pressing the # key to save their voicemail, they’ll
be prompted whether they wish to re-record or save the message.
Valid options are yes or
no . Default is no . |
saycid | If enabled, and a prompt exists in /var/spool/asterisk/voicemail/recordings/callerids,
then that file will be played prior to the message, playing the
file instead of saying the digits of the caller ID number. Valid
options are yes or no . Default is no . |
sayduration | Determines whether to play the duration of the message
prior to message playback. Valid options are yes or no . Default is yes . |
saydurationm | Allows you to set the minimum duration to play (in
minutes). For example, if you set the value to 2 , you will not be informed of the
message length for messages less than 2 minutes long. Valid
values are whole numbers. Default is 2 . |
searchcontexts | For applications such as Voicemail() , VoicemailMain() , and Directory() , the voicemail context is
an optional argument. If the voicemail context is not specified,
then the default is to only search the default context. With this option
enabled, all contexts will be searched. This comes with a caveat
that, if enabled, the mailbox number must be unique across all
contexts—otherwise there will be a collision, and the system
will not understand which mailbox to use. Valid options are
yes and no . Default is no . |
sendvoicemail | Allows the user to compose and send a voicemail message
from within the VoicemailMain() application. Available
as option 5 under the advanced menu. If this option is disabled,
then option 5 in the advanced menu will not be prompted. Valid
options are yes or no . Default is no . |
tempgreetwarn | Enables a notice to the user when their temporary
greeting is enabled. Valid options are yes or no . Default is no . |
tz | Sets the time zone for a voicemail user (or globally).
See /usr/share/timezone for
different available time zones. Not applicable if envelope= no . |
volgain | The volgain option
allows you to set volume gain for voicemail messages. The value
is in decibels (dB). The sox
application must be installed for this to work. |
There are two primary dialplan applications provided by the
app_voicemail.so
module in Asterisk. The first, simply
named VoiceMail()
, does exactly what
you would expect it to, which is to record a message in a mailbox. The
second one, VoiceMailMain()
, allows a
user to log into a mailbox to retrieve messages.
When you want to pass a call to voicemail, you need to provide two
arguments: the mailbox (or mailboxes) in which the message should be
left, and any options relating to this, such as which greeting to play
or whether to mark the message as urgent. The structure of the VoiceMail()
command is this:
VoiceMail
(mailbox
[@context
][&mailbox
[@context
][&...]][,options
])
The options you can pass to VoiceMail()
that provide a higher level of
control are detailed in Table 8-5.
Argument | Purpose |
---|---|
b | Instructs Asterisk to play the busy greeting for the mailbox (if no busy greeting is found, the unavailable greeting will be played). |
d([c]) | Accepts digits to be processed by context c . If the context is not specified, it
will default to the current context. |
g(#) | Applies the specified amount of gain (in decibels) to the recording. Only works on DAHDI channels. |
s | Suppresses playback of instructions to the callers after playing the greeting. |
u | Instructs Asterisk to play the unavailable greeting for the mailbox (this is the default behavior). |
U | Indicates that this message is to be marked as urgent. The most notable effect this has is when voicemail is stored on an IMAP server. In that case, the email will be marked as urgent. When the mailbox owner calls in to the Asterisk voicemail system, he should also be informed that the message is urgent. |
P | Indicates that this message is to be marked as priority. |
The VoiceMail()
application sends the caller to
the specified mailbox, so that they can leave a message. The mailbox
should be specified as mailbox
@
context
, where
context
is the name of the voicemail context
(not the dialplan context). The option letters b
or u
can
be added to request the type of greeting. If the letter b
is used, the caller will hear the mailbox
owner’s busy message (if one exists). If the letter
u
is used, the caller will hear the
mailbox owner’s unavailable message (also assuming
one exists). If no greeting exists, the system will generate a generic
message: The person at extension <mailbox> is
unavailable. Please leave a message at the tone.
In the dialplan we built in Chapter 6, we created several extensions. Consider
this simple example extension 102, which allows people to call UserB_DeskPhone
:
exten => 102,1,Dial(${UserB_DeskPhone},10) same => n,Playback(vm-nobodyavail) same => n,Hangup()
We faked a voicemail by playing a
prompt that didn’t actually do anything. Let’s change that so the call
goes to an actual mailbox instead. For now we’ll just let voicemail play
a generic greeting that the caller will hear. Remember, the second
argument to the Dial()
application is
a timeout. If the call is not answered before the timeout expires, the
call is sent to the next priority. We’ve got a 10-second timeout, and a
new priority to send the caller to voicemail after the dial
timeout:
exten => 102,1,Dial(${UserB_DeskPhone},10) same => n,Voicemail(${EXTEN}@default,u)) same => n,Hangup()
We can do more if we wish, and change
it so that if the user is busy (on another call), the caller will hear a
busy message. To do this, we will make use of the ${DIALSTATUS}
variable, which contains one of
several status values (type core show
application Dial
at the Asterisk console for a listing of
all the possible values):
exten => 102,1,Dial(${UserA_SoftPhone}) same => n,GotoIf($["${DIALSTATUS}" = "BUSY"]?busy:unavail) same => n(unavail),VoiceMail(101@default,u) same => n,Hangup() same => n(busy),VoiceMail(101@default,b) same => n,Hangup()
Now callers will get voicemail (with
the appropriate greeting) if the user is either busy or unavailable. An
alternative syntax is to use the IF()
function to define which of the unavailable or busy messages to
use:3
exten => 103,1,Dial(${UserB_SoftPhone}) same => n,Voicemail(${EXTEN}@default,${IF($["${DIALSTATUS}" = "BUSY"]?b:u)}) same => n,Hangup()
A slight problem remains, however, in that our users have no way of retrieving their messages, nor setting their greetings or any other voicemail options. We will remedy that in the next section.
Users can retrieve their
voicemail messages, change their voicemail options, and record
their voicemail greetings using the VoiceMailMain()
application. VoiceMailMain()
accepts two arguments: the mailbox number (and context if necessary),
plus a few options. Both arguments are optional.
The structure of the VoiceMailMain()
application looks like
this:
VoiceMailMain([mailbox
][@context
][,options
])
If you do not pass any arguments to
VoiceMailMain()
, it will play a
prompt asking the caller to provide their mailbox number. The options
that can be supplied are listed in Table 8-6.
Argument | Purpose |
---|---|
p | Allows you to treat the mailbox parameter as a prefix to the mailbox number. |
g( | Increases the gain by # decibels when playing back
messages. |
s | Skips the password check. |
a( | Starts the session in one of the following voicemail
folders (defaults to 0 ):
|
To allow users to dial an extension to check their voicemail, you could add an extension to the dialplan like this:
exten => *98,1,NoOp(Access voicemail retrieval.) same => n,VoiceMailMain()
Any user whose device is assigned to the
[sets]
context can now dial *98, and they’ll be able
to log into their mailbox to listen to messages, record their name, set
their greeting, and so forth.
Figure 8-1
shows the standard keymap configuration for Asterisk Mail. Some options may be enabled or
disabled based on the configuration of voicemail.conf (e.g., envelope=no
). This can be
given to users as a reference.
One last feature of the Asterisk voicemail system that we
should cover is the dial-by-name directory. This is created with the
Directory()
application. This
application uses the names defined in the mailboxes in voicemail.conf to present the caller with a
dial-by-name directory of users.
Directory()
takes up to three arguments: the
voicemail context from which to read the names, the optional dialplan
context in which to dial the user, and an option string (which is also
optional). By default, Directory()
searches for the user by last name, but passing the f
option forces it to search by first name
instead. Let’s add two dial-by-name directories to the TestMenu
context of our sample dialplan, so
that callers can search by either first or last name:
exten => 4,1,Dial(${UserB_SoftPhone},10) same => n,Playback(vm-nobodyavail) same => n,Hangup() exten => 8,1,Directory(default,sets,f) exten => 9,1,Directory(default,sets) exten => i,1,Playback(pbx-invalid) same => n,Goto(TestMenu,start,1)
If you call 201, and then press 8, you’ll get a directory by first name. If you dial 9, you’ll get the directory by last name.
When Asterisk first came out, it did something very simple that was nevertheless revolutionary within the PBX market of the time. None of the major PBX brands could figure out how to effectively send voice messages to email (which, put simply, is just sending an email with the message itself as a WAV file attachment). Sure, some manufacturers offered the functionality, but it was needlessly complex, unreliable, and expensive. Asterisk cut through all that nonsense and just allowed a mailbox to have an assigned email address, and messages would simply be sent through the normal email mechanisms of Linux. This proved both simple and effective, and really showed how out-of-date and out-of-touch the traditional PBX manufacturers were.
Unfortunately, in every great story there’s always a bad guy, and in this case a whole epidemic of them: spammers nearly brought the internet to its knees. The simple SMTP relay could no longer be trusted, as any machine open to relaying email would quickly become a vector for spam.
So, email became far more complex. If you want to send email from your Asterisk system, you have three fundamental ways to do that, as shown in Table 8-7.
Method | Cons | Pros |
---|---|---|
1. Send email in the clear, directly to the SMTP port of the MX record the target domain returns. Almost guaranteed to fail. | Downstream spam filters will tend to discard suspicious traffic, and this traffic will look very suspicious. | No configuration required on the Asterisk server. |
2. Relay your email through a host that knows and trusts your system. Solid DNS and mail server skills are required by the team handling the relay server. | The downstream relay server will need to be configured to work correctly with this arrangement (it will need to trust email relayed from your Asterisk server). | Relatively simple to configure on the Asterisk server. |
3. Create a normal user account on an email server (complete with a valid email address), and send emails as an authenticated user through that platform. We recommend this method since it tends to work very well, and the requirements can be easily communicated to the team that maintains your email. | Slightly more complicated to set up on the Asterisk server. | Easy to set up an email account for Asterisk: you just have to create a user on your email system named “Company PBX” or some name that identifies it, and then use the credentials for this user to send all email through. |
Essentially, what you need to do is make sure the Mail Transport
Agent (MTA)4 of your Asterisk server can send email from the asterisk
shell/user account. The Asterisk
voicemail engine will use the same mechanisms to send your voicemail to
email.
For further information on the subject of MTAs, you’ll want to consult a Linux administration book such as UNIX and Linux System Administration Handbook, 5th Edition, or an MTA-specific title such as O’Reilly’s Postfix: The Definitive Guide.
The storage of messages on traditional voicemail systems has always tended to be overly complicated.5 Asterisk not only provides you with a simple, logical filesystem-based storage mechanism, but also offers a few extra message storage options.
By default, Asterisk stores voice messages in the spool, at
/var/spool/asterisk/voicemail/<voicemailcontext>/<mailbox>.
The messages can be stored in multiple formats (such as
wav
and wav49
), depending on what
you specified as the format
in the
[general]
section of your voicemail.conf file. Your greetings are also
stored in this folder.
Asterisk does not create a folder for any mailboxes that do not have any recordings yet (as would be the case with a new mailbox), so this folder cannot be used as a reliable method of determining which mailboxes exist on the system.
Figure 8-2 shows an example of what might be in a mailbox folder. This mailbox has no new messages in the INBOX, has two saved messages in the Old folder, and has busy, unavailable and name (greet) greetings recorded.
For each message, there is a matching msg####.txt file, which contains the envelope information for the message. The msg####.txt file is also critically important for message waiting indication (MWI), as this is the file that Asterisk looks for in the INBOX to determine whether the message light for a user should be on or off.
Some organizations prefer to manage voicemail as part of their email system. This has been called unified messaging by the telecom industry, and its implementation has traditionally been expensive and complex. Asterisk allows for a fairly simple integration between voicemail and email, either through its built-in voicemail-to-email handler, or through a relationship with an IMAP server. We don’t recommend IMAP integration simply because it’s a lot of work for very little gain, and it is out of scope for this book.
It is possible to configure Asterisk voicemail to store messages as blobs within a database. This was originally seen as a simple way to allow synchronization of messages between systems. We’ve never been fans of the idea, since databases are not designed for bulk storage of binary data, and there are many other ways to synchronize files across systems.
Asterisk’s voicemail system is a mature and capable module, and an essential part of any PBX. It’s not likely to be enhanced beyond what it does, but that’s not likely to be a problem, either.
1 This name was a play on words, inspired in part by Nortel’s voicemail system Meridian Mail. Nortel (and Meridian Mail) are gone, but Comedian Mail soldiers on.
2 Also sometimes called a Message Transfer Agent.
3 We’ll dive into functions like IF()
in Chapter 10.
4 Popular MTAs these days are Postfix and Exim. The ubiquitous sendmail still exists as well, although its popularity has waned in the past few years. You’ll find Postfix on your RHEL/CentOS machines by default, and likely Exim on your Debian/Ubuntu platforms (although Postfix is often recommended as the MTA there too).
5 Nortel used to store its messages in a sort of special partition, in a proprietary format, which made it pretty much impossible to extract messages from the system, or email them, or archive them, or really do anything with them. Ah, the good old days of closed, proprietary systems. We miss ... no ... wait ... we do not miss them!