Skip to content

How To: Configure Asterisk to Send Voicemail Email via Gmail SMTP Guide

by Jon on July 15th, 2011

I created this guide to config asterisk to send voicemail’s via gmail since I didn’t find any complete guides out there. This is the quickest and easiest way to configure asterisk to email voicemail messages.

1. Uninstall sendmail and postfix if they are installed.

yum remove postfix
Loaded plugins: fastestmirror, presto
Setting up Remove Process
Resolving Dependencies
--> Running transaction check
---> Package postfix.x86_64 2:2.7.4-1.fc14 set to be erased
---> Package sendmail.x86_64 8.14.4-10.fc14 set to be erased
--> Finished Dependency Resolution

2. Install Extra Packages for Enterprise Linux repository.

rpm -Uvh http://ftp.osuosl.org/pub/fedora-epel/5/i386/epel-release-5-4.noarch.rpm

3. Install ssmtp on the server.

yum -y install ssmtp
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package ssmtp.x86_64 0:2.61-15.fc14 set to be installed
--> Finished Dependency Resolution

4. Backup the default ssmtp.conf file so we can create a new one with our gmail account.

cd /etc/ssmtp
mv ssmtp.conf ssmtp.conf.org
touch ssmtp.conf

5. Create a new config for ssmtp and add the gmail account to it by pasting in the below config and modify the email address and password.

# /etc/ssmtp/ssmtp.conf
# ssmtp config for gmail or google apps account
mailhub=smtp.gmail.com:587
hostname=voicemail@your-domain-name.com
root=voicemail@your-domain-name.com
AuthUser=voicemail@your-domain-name.com
AuthPass=Enter-Password
UseSTARTTLS=yes
UseTLS=yes
FromLineOverride=yes

6. Next you will need to add an entry for the root user to the revaliases file.

# /etc/ssmtp/revaliases
# config for asterisk to email voicemail messages
root:voicemail@your-domain-name.com:smtp.gmail.com:587

7. Now you can test sending a message from the command line.

[root@phone-call /]# ssmtp email.address@jonathanmanning.com
To: email.address@jonathanmanning.com
From: voicemail@your-domain-name.com
Subject: Test Mail Connection

The mail was sent from my Linux server

[use CTRL + d to send email]

8. Asterisk needs to be configured to use ssmtp to email voicemails, to do this we are going to edit voicemail.conf in the asterisk directory.

; /etc/asterisk/voicemail.conf
; configure asterisk voicemail to use ssmtp to use a gmail account
[general]
format = wav
attach = yes
delete = yes
maxmsg = 1000
envelope = yes
skipms = 3000
maxsilence = 10
silencethreshold = 128
maxlogins = 3
emaildateformat = %A, %B %d, %Y at %r

mailcmd=/usr/sbin/ssmtp -t
fromstring=Phone Greetings VM
pagerfromstring=Phone Greetings VM

[default]
4400 => 123456,4400,myemailaddress@jonathanmanning.com,emailaddress2@gmail.com,attach=yes|delete=1
4401 => 123456,4401,myemailaddress@jonathanmanning.com,emailaddress2@gmail.com,,attach=yes

9. Just reload the voicemail config or restart asterisk and it will now email any new voicemail’s.

[root@phone-call /]# asterisk -r
Asterisk 1.4.41.1, Copyright (C) 1999 - 2010 Digium, Inc. and others.
Created by Mark Spencer
Asterisk comes with ABSOLUTELY NO WARRANTY; type 'core show warranty' for details.
This is free software, with components licensed under the GNU General Public
License version 2 and other licenses; you are welcome to redistribute it under
certain conditions. Type 'core show license' for details.
=========================================================================
Connected to Asterisk 1.4.41.1 currently running on phone-call (pid = 10713)
phone-call*CLI> module reload app_voicemail.so
phone-call*CLI> exit
[root@phone-call /]#

If you have any problems or a suggestion post a comment!

Update 09/26/2012: I just added a new post on how to play messages in your gmail account without downloading the wav file. Click here for the post.

Update 9/17/2014: Some users experienced an issue with the smtp server not responding due to a bug in the ssmtp app. If you get the following error:

ssmtp: Cannot open smtp.gmail.com:587

You will need to add the following line to your /etc/ssmtp/ssmtp.conf config file.

TLS_CA_File=/etc/pki/tls/certs/ca-bundle.crt

You can read about the bug here, https://bugzilla.redhat.com/show_bug.cgi?id=1004998.

From → Linux, VOIP

18 Comments
  1. wow… it’s great.. i never try to connect voice mail asterisk to mail from google …. actually i connected my asterisk voice mail to own mail server like zimbra … thanks for your post…

    • No problem, this is great because I know a lot of people who use google apps for their email hosting and this tutorial will work with gmail and google apps email addresses.

  2. gianni permalink

    Hello Friend,

    I have a problem, the email is send but only at the Pager Email Address and the email normal is not send. I have write in the box

    Email Address: My email
    Pager Email Address: My email

    The result i receive the pager email without file wav :-(

    I have trixbox System Status Version: 2.6.2.5

    Help me

    • I wrote this post to be used with an asterisk install from source. It should also work with trixbox but I couldn’t tell you why yours is not working, you might want to consult some tirxbox guides.

  3. Carl permalink

    I have an annoying problem. I followed the above instructions, and it did resolve my issue with Trixbox no longer emailing voicemails. For which I am grateful.
    My problem is, now I get every Cronjob and Logwatch message emailed to me as well. Any idea how to just disable the Cronjob and Logwatch emails from being sent? I get something like 5–7 a day. Thanks for you help!

    Carl

    • Hi Carl,

      To stop the cron messages edit the crontab file with the following commands and add this entry to the top of the file mailto=””.

      This will open the crontab file in edit mode:

      crontab -e

      Depending on your distribution will determin what editor it will open in, most will open in VI, so press the “a” key to insert text, then type in mailto=”” and press the esc key. Now you are in the VI prompt, type wq and enter key which will write(save) and quit.

      Now you can double check your edit by using the following command:

      crontab -l

      Let me know if you have any questions.

      Jon

  4. David permalink

    I have a problem with a attachment. When sombody of my users leaves a message to another user, in email only a text no attachments. How can fix this? any suggestions?

    • Hi David,

      If you want the voicemail attached on the email you will need to use the following settings in /etc/asterisk/voicemail.conf. In particular the code that attaches the wav file to the email is “attach=yes” make sure your voicemail.conf has that setting for all mailboxes. Only the first email address will get the attachement, the second email address is a pager address which will only send the text email.

      4400 => 123456,4400,myemailaddress@jonathanmanning.com,emailaddress2@gmail.com,attach=yes|delete=1
      4401 => 123456,4401,myemailaddress@jonathanmanning.com,emailaddress2@gmail.com,,attach=yes
      

      Jon

  5. I love these article, im very happy

  6. jig1t permalink

    Thanks a lot!

  7. Joe permalink

    Brother, thank you so much! No other tutorial was able to get us operational, but yours was perfect.

  8. Ryan permalink

    I got the email + voicemail attachment to work, but now several users cannot call each other – it just goes straight to voicemail. Any ideas?

  9. Ryan permalink

    Also…Elastix no longer shows up.

  10. Raj permalink

    Hi jonathan,

    Great tutorial but i just want to check can i receive intrusion detection and other asterisk email notification with ssmtp? currently i’m using postfix for voicemail and for other asterisk notification, it worked but when i receive voicemail email it replace my email address name to Asterisk PBX.

    Can this change with ssmtp?
    And also can ssmtp work with other asterisk notification do i require any configuration for that? sorry for asking this kind of questions, I’m new for linux.

  11. Laurence Schenk permalink

    Thanks for the article.
    I had one problem with ssmtp: it produce the error:
    ssmtp: Cannot open smtp.gmail.com:587

    I had to add the line:
    TLS_CA_File=/etc/pki/tls/certs/ca-bundle.crt
    then every thing was happy.

    FYI if you get this error!

    Laurence

  12. Amir permalink

    Thanks for this post. I have a problem which is when I send an email it goes to spam folder. any suggestion?

  13. Brad permalink

    Thanks for the great article!

    I’m trying to set this up and am receiving an error I can’t seem to fix

    ssmtp: Authorization failed (535 5.7.8 http://support.google.com/mail/bin/answer.py?answer=14257 jj6sm4838132igb.15 – gsmtp)

    I was receiving the error:
    ssmtp: Cannot open smtp.gmail.com:587

    but fixed it by adding this to ssmtp.conf:
    TLS_CA_File=/etc/pki/tls/certs/ca-bundle.crt

    Now the new error is showing up. Any idea how to fix this? I have tried changing passwords on my gmail account and following all the advice at the link in the error message with no luck.

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS

%d bloggers like this: