[wiki:howto <- Back to the HOWTO section] = How to set-up fetchmail = * Audience: Advanced E-Mail setup * Requires: MacPorts >= 1.6, mail/fetchmail, shells/zsh == Introduction == This How-to is part of the [wiki:howto/SetupFetchmail Fetchmail] -> [wiki:howto/SetupPostfix Postfix] -> [wiki:howto/SetupDovecot Dovecot] advanced e-Mail set-up. [wikipedia:Fetchmail fetchmail] fetchmail is program used to collect e-mail from [wikipedia:Internet_service_provider internet service provider] and transfers them to the local [wikipedia:Mail_transfer_agent mail transfer agent] for further distribution. [wikipedia:Fetchmail fetchmail] can collect mail from various sources and for multiple users. With the setup described here the user does not need to start an [wikipedia:Email_Client] for collection to happen. In fact the user does not even need to be logged in. == Installation == First set-up a mail storage and a [wikipedia:Mail_transfer_agent mail transfer agent] . See [wiki:howto/SetupDovecot Dovecot] and [wiki:howto/SetupPostfix Postfix] a possible set-up. Fetchmail will not work without and you can lose your mail if those components are not set-up properly. === Z-Shell === Install Z-Shell if you are planning to use the attached command files: {{{ sudo port install zsh }}} === Fetchmail === Then install fetchmail with {{{ sudo port install fetchmail +fetchmailconf +ssl }}} Some older OSX version may come preinstalled with fetchmail (OSX 10.5). == Configuration == Note: Do not use any of the attached files without checking / changing them with your favorite text editor. You will need to {{{chmod +x}}} the attached files in order to execute them. === Step 1: ''create user'' === Fetchmail does not need root or normal user privileges to run so it is suggested to create an unprivileged user and group for daemon based fetchmail configurations. You can use the [attachment:Make_Fetchmail_User.command] to do so. This attached shell script also has instructions to view and undo all the commands. === Step 2: ''create directories'' === Dovecot need two directories to work with - one to store the run status, one for the log files. You can use the [attachment:Make_Fetchmail_Directories.command] to create the directories. Depending on which fetchmail (macports or OSX) is used you might want to change the path names to better reflect you system set-up. ''Note:'' * The directory {{{/var/run}}} (also {{{/opt/local/var/run}}} ?) is wiped every boot. I suggest using {{{(/opt/local)/var/fetchmail}}} instead of {{{(/opt/local)/var/run/fetchmail}}}. === Step 3: ''set-up configuration'' === Next you need to set up [attachment:fetchmailrc]. You find the file in {{{/opt/local/etc}}} (macports) or {{{/private/etc}}}. The file should be owned by _fetchmail:_fetchmail and only be readable to _fetchmail an no one else. {{{ sudo chown _fetchmail:_fetchmail /private/etc/fetchmailrc }}} As a starting point you can use [attachment:fetchmailrc]. You will need to add all your mail source to [attachment:fetchmailrc]. ''Note:'' * The "ID-file" is used to store the message IDs of messages already downloaded. If you use the {{{keep}}} option with one of your mail sources to ''not'' delete messages on the server after downloading them the ID-file is used to prevent downloading these messages again on the next run of fetchmail. Do not put this file in a directory under {{{(/opt/local)/var/run}}} as suggested in [attachment:fetchmailrc] as it will be deleted the next time your machine (re)boots which will result in duplicating your emails! === Step 4: ''starting the daemon'' === Fetchmail is started using {{{launchd}}} which is controlled by the attached [attachment:org.macports.fetchmail.plist]. Depending on which fetchmail (macports or OSX) is used you might want to change the path names to better reflect you system setup. The attached [attachment:Restart_Fetchmail.command] command will stop and restart fetchmail which forces a re-read of the configuration files and triggers an immediate mail collection - quite helpful while debugging the system. ''Note:'' * The logfile defined in [attachment:fetchmailrc] can only be used without {{{--nodetach}}} (see [http://fetchmail.berlios.de/fetchmail-man.html#24 man fetchmail]). With the configuration currently presented here everything will be logged to the system log. === Step 5: ''testing the deamon'' === '''Before using fetchmail you should collect all your mail by conventional means.''' After starting fetchmail you should check if the start was successful by checking the syslog: {{{ $ syslog Thu Jun 5 21:20:42 macpro sudo[42916] : martin : TTY=ttys001 ; PWD=/opt/local/Applications/Utilities ; USER=root ; COMMAND=/bin/launchctl unload -w /Library/LaunchDaemons/org.macports.fetchmail.plist Thu Jun 5 21:20:42 macpro sudo[42917] : martin : TTY=ttys001 ; PWD=/opt/local/Applications/Utilities ; USER=root ; COMMAND=/bin/launchctl load -w /Library/LaunchDaemons/org.macports.fetchmail.plist Thu Jun 5 21:20:42 macpro sudo[42919] : martin : TTY=ttys001 ; PWD=/opt/local/Applications/Utilities ; USER=root ; COMMAND=/bin/launchctl start org.macports.fetchmail Thu Jun 5 21:20:42 macpro org.macports.fetchmail[42918] : fetchmail: starting fetchmail 6.3.8 daemon Thu Jun 5 21:20:48 macpro org.macports.fetchmail[42918] : fetchmail: sleeping at Thu, 05 Jun 2008 21:20:48 +0200 (CEST) for 1800 seconds }}} Last you send yourself a mail and trigger a mail collection with [attachment:Restart_Fetchmail.command] and then check if the mail arrived in your local mail storage. == Optional Parts == [wiki:howto <- Back to the HOWTO section]