Linux tip: forward email from M$ Exchange Server to GMail

My work email has migrated to M$ Exchange Server, with M$ Outlook Web Access. Eurgh. No more POP3 retrieval to my GMail account.

I restored sanity using an Ubuntu server as follows. Needless to say, this requires that (a) the exchange server allows IMAP access and (b) the SMTP server for your machine will relay mail outside of your domain.

Updated: to do it all via procmailrc, without .forward
Updated: to poll folders other than Inbox

  1. Install fetchmail and edit /etc/fetchmailrc:
  2. sudo apt-get install fetchmail
    sudo nano -w /etc/fetchmailrc

  3. Make /etc/fetchmailrc look something like this:
  4. set daemon 300
    poll your.exchange.server protocol imap username “user” password “pass” smtpname “user@gmail.com” ssl

    replacing your.exchange.server, user (exchange), pass (exchange) and user@gmail.com (your GMail) as appropriate.

    To poll folders other than “Inbox”, you can append the “poll” line in fetchmailrc with the term “folder” and a comma-separated list of names, e.g.:

    poll your.exchange.server protocol imap username “user” password “pass” smtpname “user@gmail.com” ssl folder “Junk E-mail”,”Inbox”

    Just in case a real mail slipped into your Exchange junk.

    Then:

    sudo chmod 600 /etc/fetchmailrc

    Finally:

    sudo /etc/init.d/fetchmail start

and “tail -f /var/log/mail.log” to make sure that all is OK. You can also try “fetchmail -v” first and look for output similar to that given by this handy guide.

9 thoughts on “Linux tip: forward email from M$ Exchange Server to GMail

  1. Ben

    Hey — this looks great, and I would like to use it, but I don’t think that I have the mail server set up properly on my local ubuntu machine. Do you know of any guides to do this? Thanks!

  2. Greg

    Thank you very much for the very useful tip!

    Our local university has also switched to Exchange, and I can’t stand it…

Comments are closed.