Project

General

Profile

Support #475

Using Getmail on FreeBSD

Added by Daniel Curtis about 10 years ago. Updated over 9 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Command-Line Help
Target version:
Start date:
11/12/2014
Due date:
% Done:

100%

Estimated time:
0.50 h
Spent time:

Description

Getmail is a useful tool for fetching mail from a remote mail server and delivering them to local mail account. This is useful for keeping emails concurrent between different mail servers if used as a cron job.

Install Getmail

  • Update ports tree:
    portsnap fetch extract
    
  • Install Getmail:
    cd /usr/ports/mail/getmail
    make install clean
    
  • Prepare getmail environment:
    cd
    mkdir .getmail
    cp /usr/local/share/examples/getmail/getmailrc-examples .getmail/getmailrc
    
  • Edit the .getmail/getmailrc file to suit your remote servers information.

Retrieving Emails

  • Create a separate getmail rc file for each account, and run getmail with multiple --rcfile options.
    cd ~/.getmail
    mkdir getmail.d
    
  • Create first user and deliver using dovecot
    vi ~/.getmail/getmail.d/john.getmailrc
    
    • And and the following:
      ## john@example.com
      [options]
      verbose = 0
      read_all = false
      delete = false
      
      [retriever]
      type = SimplePOP3Retriever
      server = mail.example.com
      username = john@example.com
      password = Password
      
      [destination]
      type = MDA_external
      path = /usr/local/libexec/dovecot/deliver
      arguments = ("-e", "-f", "%(sender)", "-d", "john@altservice.com")
      
  • Create next user and deliver to the users Maildir
    vi ~/.getmail/getmail.d/bob.getmailrc
    
    • And add the following:
      ## bob@example.com
      [options]
      verbose = 0
      read_all = false
      delete = false
      
      [retriever]
      type = SimplePOP3Retriever
      server = mail.example.com
      username = bob@example.com
      password = Password
      
      [destination]
      type = Maildir
      path = /var/vmail/vmail1/example.com/b/o/b/bob-2014.03.29.11.08.32/Maildir
      

Automate Getmail

  • Of course, it's really easy to script this for a large number of rc-* files. Create a script:
    vi /usr/local/bin/run-getmail.sh
    
    • And add the following containing:
      #!/bin/sh
      set -e
      cd /var/vmail
      rcfiles="" 
      for file in `ls /var/vmail/.getmail/*.getmailrc` ; do
        rcfiles="$rcfiles --rcfile $file" 
      done
      exec /usr/local/bin/getmail $rcfiles $@
      
  • Make the script executable:
    chmod +x /usr/local/bin/run-getmail.sh
    
  • Edit the vmail crontab:
    su - vmail
    crontab -e
    
    • And add the following to run the run-getmail.sh script every 2 minutes.
      */2 * * * * /usr/local/bin/run-getmail.sh
      
#1

Updated by Daniel Curtis about 10 years ago

  • Description updated (diff)
#2

Updated by Daniel Curtis about 10 years ago

  • Description updated (diff)
  • Status changed from New to Closed
  • % Done changed from 0 to 100
#3

Updated by Daniel Curtis almost 10 years ago

  • Target version set to FreeBSD 9
#4

Updated by Daniel Curtis almost 10 years ago

  • Category set to Command-Line Help
#5

Updated by Daniel Curtis over 9 years ago

  • Description updated (diff)
#6

Updated by Daniel Curtis over 9 years ago

  • Description updated (diff)
#7

Updated by Daniel Curtis over 9 years ago

  • Description updated (diff)
#8

Updated by Daniel Curtis over 9 years ago

  • Description updated (diff)
#9

Updated by Daniel Curtis over 9 years ago

  • Description updated (diff)

Also available in: Atom PDF