Asterisk, and other worldly endeavours.

A blog by Leif Madsen

Asterisk IMAP and Gmail


Today I was working on the next edition of the Asterisk book and wanted to see if I could get Asterisk IMAP voicemail support to work with Gmail. I had tried doing this a few times in the past without success, but since I had spent some time documenting and testing against Dovecot last week for another client and gotten everything working, I figured I had a good base to start trying to connect to the Gmail IMAP servers.

At first I was having problems with getting Asterisk to connect to the server as it would keep timing out when trying to connect to the Gmail IMAP servers on port 993. I looked at the instructions for connecting and double checked, and I thought I had everything right. I also made sure my IMAP library was compiled with OpenSSL support since Gmail requires you to connect via SSL.

After reading a few emails and doing more testing, I finally stumbled upon the missing link! Find below the snippet of voicemail.conf configuration that finally allowed me to connect to the Gmail IMAP system with Asterisk IMAP voicemail support.

Note: Be aware that there is a mixture of commas and pipes in the line where we’ve setup mailbox 100. This is not a typo!

; voicemail.conf
imapserver=imap.gmail.com
imapport=993
imapflags=ssl

pollmailboxes=yes
pollfreq=30

[default]
100 => 100,Leif Madsen,,,attach=no|imapuser=leif.madsen@MYDOMAIN_GOOGLE_APPS.com|imappassword=my_secret_password

I was using this with Google Apps for one of the domains we bought for working on the book, so the login is the full email address. The password is what you use for logging into the Gmail interface. Also, you need to make sure you’ve enabled IMAP support in the web interface before trying this or else your connection won’t work.

More information including step-by-step instructions on compiling IMAP support into Asterisk and configuration examples for Dovecot and Gmail will be in the upcoming book, but I was so excited to get this working today that I thought I’d share the secret sauce at least so you don’t have to wait for the whole recipe.

Connecting to Gmail was not as quick as connecting to Dovecot on a remote server I was working with. I imagine this is due to the high load Google has to deal with, so while it works, there may be some minor delays when retrieving and leaving voice messages, but nothing that caused it to be unusable.

Note: The KEY to making it work was the imapflags=ssl part. Without that you won’t get connected and will have problems with timeouts and such going on with Asterisk. Once I enabled the ssl flag I was golden.

Advertisements

Written by Leif Madsen

2010/09/20 at 10:37 am

Posted in Asterisk

Tagged with , , , , , , ,

7 Responses

Subscribe to comments with RSS.

  1. Dear Leif,
    It seems that every one who wants to use gmail as his voicemail email account have to give his gmail passwork to Asterisk administrator . Am I right?

    Omid

    2010/09/21 at 8:46 am

    • Yes, I’m not sure how else authentication would be done.

      Leif Madsen

      2010/09/21 at 8:57 am

      • every email server that require authentication will have the same issue, that’s why we use different SMTP server for deliver voicemail then the client’s SMTP server.

        If I just want to send to gmail/google apps, it does not matter what is the SMTP server, only if I want to send it using gmail it will matter.

        ik_5

        2010/09/29 at 4:00 am

        • I’ve actually discussed part of this with the Digium development team, and there should be some changes in the future for multiple configuration files that require user information for authentication to external services.

          The change I suggested (which is probably the easiest) is to provide md5secret fields for all of those configurations. So instead of having to provide a plain-text password, the password field for the user can at least be submitted as a hash instead of plain-text.

          Leif Madsen

          2010/09/29 at 7:10 am

    • Hi Omid and Leif,

      It’s probably not the best solution but you can configure Asterisk to store the voicemails into dummy IMAP accounts and then run a script (or process or whatever) that import that voicemail into the final user’s Gmail account by using Google Apps Email Migration API. It will work *only* with Google Apps for business or education as far as I know and you can use an administrator account to do the magic (see this doc http://code.google.com/googleapps/domain/email_migration/developers_guide_protocol.html). This way you never have to ask users for passwords nor store them into Asterisk’s configuration files.
      Kind of over-elavorate, but might work for someone.
      Regards.

      Pablo Saro

      2012/02/23 at 8:12 pm

      • Thanks for the post Pablo! While that may be overly elaborate for the standard cases, the ones in which the ability to store or request credentials from a customer (lets say you were building some sort of public, hosted solution), that ma be a work around.

        You’ve also made me wonder if there is an API where the client can authenticate from a web interface once, which then generates an API token or key that can then be used to talk to Google to store information into the account. While that information certainly still needs to be stored somewhere, it might be enough for people who simply don’t want their password being stored.

        (I’m thinking the situation where you go to a website and authenticate via twitter, Google, etc.)

        Leif Madsen

        2012/02/24 at 7:41 am

  2. […] The busiest day of the year was September 29th with 449 views. The most popular post that day was Asterisk IMAP and Gmail. […]


Comments are closed.

%d bloggers like this: