• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 805
  • Last Modified:

Setting up Fetchmail and Cyrus

Fedora Core 3:
Cyrus and Postfix
Authentication done via MySQL (no local UNIX user mailboxes)

How do I setup Fetchmail to do the following:  
Collect mail for about 70+ users  from 4 Exchange servers using POP3 and dump it into a corresponding Cyrus user mailbox on the local server.   This proccess should be repeated every 8 minutes from 6AM to 11PM evey day.

For example:

poll sXXXXex31.stXXXs.com proto pop3 port 110
        user "personp1" with pass "secret1" is "pperson1" here
        user "personp3" with pass "secret3" is "pperson3" here
poll sXXXXexc32.stXXXs.com proto pop3 port 110
        user "personp2" with pass "secret1" is "pperson2" here
        user "personp4" with pass "secret2" is "pperson4" here


0
tuaris
Asked:
tuaris
  • 2
1 Solution
 
jlevieCommented:
To avoid problems with missed email and email delivered to the wrong user each account needs it own fetchmail config and you need to run a fetchmail process for each user. That means that you must have Linux accounts for each mail user. The accounts can be locked and fetchmail will work as long as each account has a login directory and valid shell. If you want to go this way there's a SysV init script below that will start this for each user at boot. See the comments at the top for usage.

Another possibility would be to use one of the mail migration tools to connect directly to the exchange servers and inject the transferred message into the user's mailbox via IMAP. One such example that might work would be http://freshmeat.net/projects/mbcp/ and there are other tools in the UWash IMAP kit.

--Save as /etc/init.d/fetchmail and make it executable---
#!/bin/bash
#
# This shell script takes care of starting and stopping
# fetchmail for a user accounts. Each email account needs to have
# a fetchmail rc file in /usr/local/etc named fetchmail.username. This
# script wil isolate the username from the filename so that the fetchmail
# process for that account can be run by that user. A simple
# fetchmail.username might look like:
#
#   set daemon 1800
#   poll mail.my-isp.net proto pop:
#   user "ispacct" with pass "tweecagi" is "username" here;
#
# Each fetchmail.username file must be owned by the local user and be
# readable only by that user (mode 600). See 'man fetchmail' for more
# information.
#
# chkconfig: 2345 81 29
# description: Fetchmail is a tool for retrieving the mail from remote
#              servers via POP3 or IMAP for users and inserting that
#              mail into the local mail system.
# processname: fetchmail

# Source function library.
. /etc/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

binary=/usr/bin/fetchmail
[ -f $binary ] || exit 0
#
# Simple function to get the PID of an arbitrary process
#
pidof() { ps -efw|grep $1|grep -v grep|tr -s ' '|cut -d ' ' -f 2; }

RETVAL=0
prog="fetchmail"
start() {
      # Start Daemon
        # Loop through the individual fetchmail rc files

        for f in /usr/local/etc/fetchmail.*; do
          user=`echo $f | sed -e "s/.*fetchmail\.\(.*\)/\1/"`
        echo -n $"Starting $prog for $user: "
        pid=`pidof $f`
        if [ $pid ]; then
          echo
          else
            su $user -c "$binary -f $f"
          RETVAL=$?
          if [ $RETVAL -eq 0 ]; then
              echo_success
              touch /var/lock/subsys/$prog
          else
              echo_failure
            fi
          echo
        fi
      done
        return $RETVAL
}

stop() {
      # Stop daemons.
        for f in /usr/local/etc/fetchmail.*; do
          user=`echo $f | sed -e "s/.*fetchmail\.\(.*\)/\1/"`
        echo -n $"Shutting down $prog for $user: "
        pid=`pidof $f`
        if [ $pid ]; then
          kill $pid
          echo_success
          else
          echo
        fi
        echo
      done
      RETVAL=0
      [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
      return $RETVAL
}

# See how we were called.
case "$1" in
  start)
      start
      ;;
  stop)
      stop
      ;;
  restart|reload)
      stop
      start
      RETVAL=$?
      ;;
  *)
      echo $"Usage: $0 {start|stop|restart}"
      exit 1
esac

exit $RETVAL
0
 
tuarisAuthor Commented:
Local Linux User accounts isn't an option in my case.  I won't be the only person administring this server.  Other less knowedgeable people need to have the ability to easily add email users.  The MySQL method ensures this.

So A linux based email server can't do this with fetchmail alone and without adding users to the system?  What is this problem about "missed email and email delivered to the wrong user"?

The people in charge of the Exchange server have some form of serious brain damage, becuase they disabled IMAP access  and force everyone to use only Outlook.  However, they are unknowingly allowing the POP3 server to function.  So the only form of getting mail of these servers is through POP3.

Can't fetchmail talk directly to Cyrus? or if that is not possible use Postfix?
0
 
jlevieCommented:
Given that you'll have all of the user names & passwords in a MySQL database it would be pretty easy to automate the creation/deletion of the Linux accounts and user fetchmail script. Either that or make it a part of the Cyrus account creation.

I can't remember the exact details, but there was a note in the full Fetchmail doc's that cautioned against trying to run fetchmail as other than the user.

Fetchmail only "talks" to the MTA. What it actually does is to retrieve each message from the remote server and then create a new message to the local user and send that via the local MTA. A mail copy tool can talk POP or IMAP to the remote and IMAP to Cyrus and thus bypass the MTA.
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now