VoiceMail to Email using postfix

Here is the simple postfix configuration to make it work with freepbx.

The main config file to edit is: /etc/postfix/main.cf

# information on enabling SSL in the smtp client.
myhostname = ippbx.pbx.lan
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = mail.mehrdust.my, ippbx.pbx.lan, localhost.pbx.lan, localhost
relayhost = [mail.mehrdust.my]:587 # use 587 to send mail to gmail
# (default smtp port is 25)
mynetworks = [::ffff:]/104 [::1]/128
mailbox_command = procmail -a "$EXTENSION"
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all

To change the sender email address and sender information edit: /etc/asterisk/vm_general.inc

fromstring=Voicemail System
pagerfromstring=Voicemail System

Postfix Management

Postfix files messages into several queues. The main ones are the following:

  • Incoming/Active – These are the common queues where incoming/outgoing messages live until they finish being delivered or received.
  • Deferred – If messages cannot be delivered they go here and delivery is reattempted until the messages expire.
  • Hold – A queue that you the administrator can move messages to. Messages placed here are not processed, no attempt is made to redeliver them, and they do not expire. As far as I can tell this queue only exists to make life easy on the administrator and gives you a safe place to store things temporarily.

To see the queue run: mailq

Here is a sample mailq, and here is postfix folder for one instance.

Sometimes an email server will get crushed with volume from an attack, a misconfiguration, a mistake, or something similar and your machine will peg itself at full load while it tries to move the messages. This is when


shines. There is a lot more to postfix and postsuper but these three commands can help you save your server and the people that depend on it for email in certain situations.

  • postsuper -d

    (deletes messages)

  • postsuper -h

    (move messages to Hold queue)

  • postsuper -r

    (requeue messages, can requeue messages in Hold to Incoming/Active)

Each of the above commands take a third argument ‘queue_id’. This value can be ALL (must be all caps) to tell it to apply the operation to all messages in all queues, a dash (-) to tell it to apply the operation to queue_ids provided at stdin, or a specific message’s queue_id. The stdin option is especially nice as you can create a file with a queue_id on each line and then have postsuper process all of those messages in one run. You can also do ALL [queue name in lowercase] to apply the operation to all messages in a specific queue. For example,

postsuper -d ALL hold

would delete all messages in the Hold queue. Do NOT leave the queue name off if you are trying to do this else the ALL will snag everything in all queues.

Using the commands above, this is how you could deal with a single host, or a small set of hosts that is slamming your server with messages. Say these messages are not important and do not need to be read but they are backing up the postfix queues and preventing delivery of real email to your users.


postsuper -h ALL
postsuper -h ALL
postsuper: Placed on hold: 5 messages
  • Pushes all messages (the junk and the valid ones) to the Hold queue so you can breathe and think.
  • Empties out the Incoming/Active queues so that new messages can be effectively delivered.
  • At this point you need to stop the hosts sending the volume you don’t want, either by blocking the hosts if it is an attack or by fixing the issues if it is a misconfiguration or issue with a server you have control over.

(2) Next you would want to delete all of the messages you don’t want from the Hold queue. There are several approaches here, but this is one:

  • Create a file containing the information on the bad messages:
    mailq | grep theEnemyHostName > bad_messages.txt
  • Write a script to generate a new file from bad_messages.txt that contains just the queue id on each line, nothing else. Use perl or whatever you are comfortable with. The queue id is generally the first chunk of output for each message printed by mailq so you likely just need to grab the first eleven characters of each line.
  • postsuper -d - < list_of_queue_ids.txt

    . This will delete all of the messages you identified.

# postsuper -d 13269432141
postsuper: 13269432141: removed
postsuper: Deleted: 1 message

# postsuper -d ALL
postsuper: Deleted: 5 messages
root@ippbx:/var/home/support# mailq
Mail queue is empty

(3) Requeue all of the remaining, valid messages with

postsuper -r ALL


postsuper -r ALL
postsuper: Requeued: 5 messages

All of the above applies to Zimbra as well. Even though it has that fancy web-based administrative interface and a real nice way to view and filter your mail queues that interface always blows up and pukes errors when I try to do an operation involving any kind of heavy message volume. So if you get in a similar jam the CLI is what you have to use. The postsuper command is also very fast so even if you have 10’s or 100’s of thousands of messages jamming things up it should not be a problem.

Source : http://blog.gtuhl.com/2008/08/14/basic-postfix-queue-management/

You may also like