Odds and Ends February 4, 2007 at 4:45 am

Mail.app Configuration Script

Script to configure client mail settings

So I thought I would post this before I grow too old and forget about it. I have been working on a command line based configuration script for Mail.app, it does some fancy things like create Mail bundles and Package installers for deployment,it still has a couple of bugs so use it wisely. I haven't had time after MacWorld to work on it too much so if you have any bug reports, feel free to post them here as well as code additions. I would like to add some ssl certificate import support.

It's big, it's long, its BASH – enjoy and dont judge me too harshly as I know it needs some work.

Grab the script here.

No Comments

  • Hey look at that I made it the front page!
    I thought I would take a few lunch minutes and elaborate on what the script
    actually does on the back end.
    The core of the script is XML injection it does this through the “defaults”
    command in a very raw fashion,for those of you wondering why I didn’t
    use PlistBuddy ,well basically there was no real need as the keys I am
    injecting where not incredibly nested and also I find the “raw” xml easier to
    read then syntax of PlistBuddy when working with complex arrays. The
    script can add an account to a pre-existing preference file or it can
    generate a fresh new copy with that account addition for a user who’s
    never opened Mail.app . As I generate new preferences there is some
    XML in there that may look a little long winded and you might wonder if it is
    safe to hard code that much information into a default preference. Well
    basically I took a preference from 10.4.7 and made in the basis for the
    “fresh” preference ,Mail.app typically generates this preference on first run
    (which can be seen by running a ktrace on Mail.app during this period.) as
    there is no real “default” preference to copy from I choose one that had
    defaults that suite most workstations(the default preference is normally the
    same for all workstations ),I also had one person ask if there would be a
    problem with generating this in 10.4.7 and reading it in say 10.4.9’s version
    of Mail.app,well the answer is no, mainly because Mail.app has to read
    previous updates preferences as there are many many scenarios where
    the users home folder and the os would be out of sync version wise such
    as a migration using the Migration Assistant.

    My original scenario for deployment was Network Home
    Directories,basically you can point it as the parent folder such as /Users/
    or /Volumes/data/Users and it will recursively go through and “inject” either
    additive (checking first to see if the config is not already there.) or a
    “fresh” config with the account added. It uses the users home directory
    name as the username for the mail server as you hopefully have your mail
    server tied into the same User Account Directory as your Home
    Directories server and Workstations.As you may have users in Open
    Directory or Active Directory the script has the ability to read in the list of
    folders in say /Users/* and check them against a directory server in your
    search path configured in Directory Access.app (man DirectoryService)
    this also helps with skipped directories such as “Shared” or “Deleted
    Users” It also allows you perform the same functionality on Address
    Book.app for its ldap servers.

    If you don’t use Network Home Directories or you use Portable (Mobile)
    Homes then the script can generate a standalone package installer for
    your as long as you have the developer tools installed. Basically it will
    copy it self in as a postflight script and read from a config file it generates
    during the creation process.You can then post this on your web server
    and allow people to download an installer that sets up Mail.app and
    Address Book.app for all users and in addition will create a Mail Account
    Bundle what I like to call templates and install it in /Library/Mail/
    AccountTypes/ , these are the templates used during new account
    creation that supply default config information for the account ,you have
    probably seen the default one for .Mac listed in the pop up menu of
    Mail.app add account window, the script will generate a package installer
    for these so that even after you install any subsequently created users will
    only have to use the template for intial config. The script actually can
    generate these with out making a package installer as well if you would
    rather deploy them in your restore image or as a Network Mount in /
    Network/Library/Mail/Account Types/. run the scripts with no arguments
    and it will show you the available options and arguments and an example
    syntax section at the bottom that will cover some of the scenarios I have
    mentioned here.I will continue to update it as its a pet project that grew out
    out of production script that I wrote for my company.

Leave a reply

You must be logged in to post a comment.