#!/bin/bash # # ForwardMails 1.0, July 2007, Andre Aulich, www.andre-aulich.de # # We need a file with a definition of our forwardings. # It should look like this: # # test1: first1.last1@keriomail.domain.de # test2: first2.last2@keriomail.domain.de # test3: first3.last3@keriomail.domain.de # test4: first4.last4@keriomail.domain.de # test5: first5.last5@keriomail.domain.de # # Make sure there's only one colon per line. # # Define the path to the Forwarders file: FORWARDERSFILE=Forwarders.txt # First, let's generate a list of users: for i in $(cat "$FORWARDERSFILE" | awk -F":" '{print $1}') # For each user we need his alias shortname in the form of # 'firstname.lastename'. Let's take this from our list: do MyForwarder="$(cat "$FORWARDERSFILE" | grep "$i" | awk -F" " '{print $2}')" # Output what we are doing: echo "Mails for $i will be forwarded to $MyForwarder." # Now, actually do it: dscl -u diradmin -P DIRADMINSPASSWORD /LDAPv3/127.0.0.1/ -create /Users/$i apple-user-mailattribute " kAPOPRequired APOPNotRequired kAltMailStoreLoc kAttributeVersion Apple Mail 1.0 kAutoForwardValue $MyForwarder kIMAPLoginState IMAPAllowed kMailAccountLocation fully.qualified.domain.name.of.your.server kMailAccountState Forward kPOP3LoginState POP3Allowed kUserDiskQuota 0 " # MAKE SURE, THAT IN THE XML PART ABOVE YOU ADAPT THE kMailAccountLocation # PART TO YOUR ENVIRONMENT! done