getmail Documentation

This is the formal documentation for getmail. If your question is not answered here or in the Frequently Asked Questions, please subscribe to the mailing list.

About this document

The official location of this document is http://www.qcc.ca/~charlesc/software/getmail-3.0/docs.html. For easy navigation, all headings in the HTML version of this document are links to their parent heading.

Table of Contents

  1. Installing getmail
  2. Configuring getmail
  3. getmailrc directives
  4. Running getmail
  5. Commandline options

Installing getmail

Follow these steps to install getmail:

  1. Download getmail.
  2. Unpack the tarball.
    tar xzf getmail-version.tar.gz
  3. Copy the contents to a suitable location:
    mkdir /usr/lib/getmail
    cp -a getmail-version/* /usr/lib/getmail/
    			
    You can install getmail in your home directory or elsewhere if you prefer. If you use a directory other than /usr/lib/getmail/, change the definition of GETMAILPATH in the getmail wrapper script or ensure the directory you choose is in your PYTHONPATH environment variable.
  4. Copy the getmail helper script to a location in your PATH, and ensure it is executable:
    cp -a getmail-version/getmail /usr/bin/
    chmod 755 /usr/bin/getmail

Configuring getmail

  1. Create a getmail configuration/data directory in your home directory:
    mkdir ~/.getmail
    You can use another path or directory name, but getmail assumes this name by default. If you choose something different, you will need to specify its name on the getmail command line with the --getmaildir option.
  2. Create a configuration file named getmailrc in the directory you created in step 1 above (see the section Configuration file below for details). You can use another file name or path, but getmail assumes this name by default. If you choose something different, you will need to specify its name on the getmail command line with the --rcfile option.

Configuration file

A getmail configuration file (typically named getmailrc, and located in $HOME/.getmail/) looks similar to an MS-Windows .INI file. For security reasons, your getmailrc file must not be group- or world-writable. getmail will refuse to run if it finds your getmailrc file is writable by others.

The file is broken into sections. Each section starts with an arbitrary label surrounded by square brackets:

[section name]

A section then contains one or more lines in name = value format. Values containing whitespace must be surrounded with single- or double-quotes. The pound sign (#) introduces a comment, which continues until the end of the line.

foo = 42
bar = "string value containing spaces"
baz = ""           # This is a comment; baz is an empty value

To include a pound sign in an option value, quote it. Percent signs (%) must be doubled; for example, if you want to specify a password of foo%bar, use the following:

password = foo%%bar

The special section [default] must be the first section in the file; it supplies default values for options in other sections. For example, to set the option verbose to 1 for all following sections, you could put it in the [default] section:

[default]
verbose = 1

[my home account]
username = foobar
password = "my password"
…

[my work account]
username = foobar
password = "my password"
…

getmail ignores whitespace surrounding the = sign. The following lines are equivalent:

account = joe.bloggs
account=joe.bloggs
account=   joe.bloggs

Option values containing single or double quote characters can be quoted with the other character:

password = "this is a more 'secure' password"

To un-set an option taking a string value, set it to the empty string:

message_log = ""         # Previously set to /var/log/getmail; turn it off for this account

Other sections in a getmail configuration file represent POP3 accounts to retrieve mail from, one per account. The section name is unimportant, but must be unique. An example account section might look like this:

[Home ISP account]
server = mailhost.isp.tld
username = brenda.bjorn
password = "my mail password"
postmaster = ~brendab/Maildir/  # Deliver all mail to the Maildir in my home directory

When getmail tries to determine the value of an option, it looks at the following, in order, until it finds a match:

  1. Options specified on the command line
  2. Options specified in an account section of the getmail configuration file
  3. Options specified in the [default] section of the getmail configuration file
  4. getmail's built-in default value

POP3 Account types

There are two different types of POP3 email accounts:

Regular mailbox

This is a typical POP3 mailbox provided by an ISP for a single user. It receives mail addressed to a single user (say, shannon.fotheringham@aqua.myisp.tld). For this type of account, the minimum configuration would be something like this:

[My Aqua Account]
server = mailhost.aqua.myisp.tld
username = shannon.fotheringham
postmaster = ~shannonf/Maildir/

This postmaster directive tells getmail to deliver all mail to Shannon's Maildir. Since a password was not configured, getmail will prompt the user for it when run.

Domain mailbox

This type of POP3 account is typically provided by an ISP to a small company or organization. It receives mail addressed to any user in a given domain. For example, mail to info@smallcompany.tld, tgrieg@smallcompany.tld, and sales@smallcompany.tld all ends up in the same POP3 domain mailbox.

getmail includes features to enable retrieval of mail from this type of account, filter it according to who the mail was addressed to, and deliver it to different destinations. A minimal configuration with this type of setup would be something like this:

[Company domain mailbox]
server = mailhost.largeisp.tld
username = small.company
password = RRt49slP32m
envelope_recipient = delivered-to:1
postmaster = ~tgrieg/Mail/postmaster-maildir/
local = tgrieg@smallcompany.tld,~tgrieg/Mail/personal-maildir/
local = info@smallcompany.tld,~bobf/Maildir/
local = sales@smallcompany.tld,~darlab/Maildir/

The local directives tell getmail to deliver mail for those users to their various mail spools on the system, and the postmaster directive tells getmail to deliver any mail which doesn't match any of the local directives somewhere else.

To make getmail sort mail (with local directives like the above) based on the envelope recipient address, you must either enable the use_*env option (if your mailhost supports it) or use the envelope_recipient directive.

Message Delivery Targets

In a getmailrc file, postmaster and local directives contain message delivery targets, which instruct getmail to delivery messages in a particular manner. A message delivery target may be a qmail-style Maildir or an arbitrary command (such as an external Message Delivery Agent or MDA).

Target TypeSyntaxNotes
Maildir/path/to/Maildir/Maildir targets must have a trailing slash
Command|/path/to/command [arguments]Command deliveries must start with a pipe (|). Remember to quote values containing whitespace.

For command deliveries, getmail provides the following environment variables.

Note the following restrictions:

Leading tilde characters (~) on paths will be expanded -- i.e. ~jason/Maildir/ likely becomes /home/jason/Maildir/ on most systems.

getmailrc Directives

getmail understands the following getmailrc directives:

DirectiveOptional?DefaultSummary
POP3 Server Configuration
serverNoNonePOP3 server hostname
portYes110POP3 server TCP port number
timeoutYes180 secondsPOP3 server TCP timeout
Account Configuration
usernameNoNonePOP3 account username
passwordYesPrompt for passwordPOP3 account password
use_apopYes0 (No)Use POP3 APOP authentication if available
Message Formatting
no_delivered_toYes0 (No)Suppress addition of Delivered-To: header field
no_receivedYes0 (No)Suppress addition of Received: header field
Message Delivery Targets
postmasterNoNoneDefault message delivery target
localYesNoneHeader field pattern-matching delivery target for domain mailboxes
envelope_recipientYesNoneSpecify a header field the POP3 server records the envelope recipient address in.
use_*envYes0 (No)Use Demon's SPDS *ENV POP3 extension to retrieve message envelopes. Overrides envelope_recipient above.
extension_sepYes-User extension address separator character
extension_depthYes1User extension address base length
Message Retrieval
readallYes1 (Yes)Retrieve all messages, or only previously unseen messages
max_message_sizeYes0 (No limit)Do not retrieve messages larger than this setting
max_messages_per_sessionYes0 (No limit)Do not retrieve more than X messages
deleteYes0 (No)Delete messages after retrieval
delete_afterYes0 (No)Delete messages X days after retrieval
getmail Behaviour
verboseYes1 (Yes)Show status messages while running
message_logYesNoneLog message retrieval and delivery to file
POP3 Server Configuration

The following directives are used to configure which POP3 servers getmail will retrieve mail from.

POP3 Server Hostname
Function Specify POP3 server to connect to.
Syntax server = hostname.domain.tld
Optional No
Default None
Commandline equivalent None
Examples server = pop3.isp.com
POP3 TCP Port
Function Specify TCP port on POP3 server to connect to.
Syntax port = portnumber
Optional Yes
Default 110 (Default POP3 port)
Commandline equivalent None
Examples port = 8110
POP3 TCP timeout
Function Specify the TCP timeout to use with an account.
Syntax timeout = value (seconds)
Optional Yes
Default 180
Commandline equivalent --timeout = value (seconds)
Examples timeout = 360
Note The TCP timeout capabilities are enabled by the timeoutsocket.py module by Timothy O'Malley. A copy of timeoutsocket.py is included with getmail; however, getmail will continue to function (without this capability) if the timeoutsocket module is not present.
timeoutsocket.py Copyright 2000,2001 by Timothy O'Malley <timo@alum.mit.edu>

All Rights Reserved

Permission to use, copy, modify, and distribute this software
and its documentation for any purpose and without fee is hereby
granted, provided that the above copyright notice appear in all
copies and that both that copyright notice and this permission
notice appear in supporting documentation, and that the name of
Timothy O'Malley  not be used in advertising or publicity
pertaining to distribution of the software without specific, written
prior permission.

Timothy O'Malley DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS, IN NO EVENT SHALL Timothy O'Malley BE LIABLE FOR
ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
POP3 Account Configuration

The following directives are used to configure which POP3 accounts getmail will retrieve mail from.

POP3 account username
Function Specify the account name for the POP3 server.
Syntax username = user
Optional No
Default None
Commandline equivalent None
Examples username = joe.bloggs
username = joe.bloggs:vhost.example.net
POP3 account password
Function Specify password to use with POP3 account
Syntax password = password
Optional Yes
Default Prompt for password
Commandline equivalent None
Examples password = "long password containing whitespace"
password = foo_bar
POP3 APOP authentication
Function Use POP3 APOP authentication if available. Falls back to USER/PASS authentication if not supported.
Syntax use_apop = bool
Optional Yes
Default 0 (USER/PASS authentication)
Commandline equivalent None
Examples use_apop = 1
use_apop = 0
Message Formatting

The following directives are specified in any getmailrc section, and are used to configure how getmail will format messages that it retrieves.

Delivered-To: header field suppression
Function Suppress the addition of a Delivered-To: header field to messages that getmail retrieves.
Syntax no_delivered_to = bool
Optional Yes
Default 0 (No)
Commandline equivalent None
Examples no_delivered_to = 1
no_delivered_to = 0
Received: header field suppression
Function Suppress the addition of a Received: header field to messages that getmail retrieves.
Syntax no_received = bool
Optional Yes
Default 0 (No)
Commandline equivalent None
Examples no_received = 1
no_received = 0
Message Delivery Targets

The following directives are specified in any getmailrc section, and are used to configure where getmail will deliver retrieved messages. Also see the section on message delivery targets.

Default delivery target
Function In non-domain mailbox operation, specifies the delivery target for all retrieved mail.

In domain mailbox operation, this specifies the default delivery target for all retrieved messages which are not handled by a matching local directive.
Syntax postmaster = target
Optional No
Default None
Commandline equivalent None
Examples postmaster = /home/joe/Maildir/
postmaster = "|/usr/local/bin/my_mda -f foo -a all -b gone /home/postmaster/.mdarc"
Header field pattern matching delivery target
Function Specify the destination for retrieved messages which have an envelope recipient address which matches a given pattern. getmail will match the specified Perl- compatible extended regular expression against the envelope recipient address (retrieved using *ENV support or found in the header field specified with the envelope_recipient directive). If a match is found, the message will be delivered to the specified target. If multiple local directives contain matching patterns, each matching target will receive a copy of the message. If there are no local directives, or no match is found, the message will be delivered according to the default delivery target.

If you do not understand Perl-compatible regular expressions, just use email addresses here. They will work in virtually all cases.

Use multiple local directives to filter mail retrieved from a domain mailbox to multiple local user accounts.

Note that local directives can only be used in multidrop mode.
Syntax local = pattern,target
Optional Yes
Default None
Commandline equivalent None
Examples local = joe@isp.tld,~joe/Maildir/
local = brenda@homeisp.tld,/home/brenda/Mail/personal/
local = brenda@workisp.tld,/home/brenda/Mail/work/
local = "^(joe|fred)@company\.(tld|dom.tld)$,|/path/to/mda -opts"
Recipient header field specification
Function Extract envelope recipient address from listed header field.

This directive enables domain mailbox operation and is useful only if the POP3 server records envelope recipient addresses in a specific header field (i.e. Delivered-To: or X-Envelope-To:).
Use it if wish to process mail from a domain mailbox, sorting and delivering it to multiple local user accounts using local directives.
Syntax envelope_recipient = fieldname:fieldnum
fieldnum refers to the occurrence of that header field; the value 2 is the second occurrence of fieldname.
Optional Yes
Default None
Commandline equivalent None
Examples envelope_recipient = Delivered-To:2
envelope_recipient = X-Envelope-To:1
SPDS *ENV POP3 Extension
Function Retrieve envelope sender and recipient addresses from the server using Demon's SPDS *ENV POP3 extension (described at http://www.demon.net/helpdesk/products/mail/sdps-tech.shtml).

This directive enables domain mailbox operation and overrides the envelope_recipient directive.
Syntax use_*env = bool
Optional Yes
Default 0 (No)
Commandline equivalent None
Examples use_*env = 1
use_*env = 0
User address extension separator character
Function Determine which part of a recipient address is the extension to the base address.

This directive is mostly useful if the POP3 server records envelope recipient addresses in a specific header field (i.e. Delivered-To: or X-Envelope-To:), and you wish to deliver mail using TMDA or another filtering MDA.

getmail will export the detected envelope recipient address in the environment variable RECIPIENT. It will then split the local-part of the address at the first occurrence of this character (default: -), and export anything after it as the environment variable EXT.

Note that you will still need a wrapper script around your filtering MDA; getmail will consider a delivery failed if the MDA returns non-zero. This is left as an excercise for the reader/user of TMDA.
Syntax extension_sep = character
Optional Yes
Default -
Commandline equivalent None
Examples extension_sep = +
extension_sep = -
User address extension base length/depth
Function Determine which part of a recipient address is the extension to the base address.

This directive is mostly useful if the POP3 server records envelope recipient addresses in a specific header field (i.e. Delivered-To: or X-Envelope-To:), and you wish to deliver mail using TMDA or another filtering MDA.

If you are using a local directive to configure delivery of mail per-recipient, getmail will export the detected envelope recipient address in the environment variable RECIPIENT. It will then remove the base part of the address at the extension_depth occurrence of the extension separator character.
Syntax extension_depth = count
Optional Yes
Default 1
Commandline equivalent None
Examples extension_depth = 2
Message Retrieval

The following directives are specified in any getmailrc section, and are used to configure how getmail will retrieve messages.

Retrieve new messages / retrieve all messages
Function Select whether to retrieve all messages, or only messages which have previously not been seen by getmail.
Syntax readall = bool
Optional Yes
Default 1 (Retrieve all messages)
Commandline equivalent --all (readall = 1)
--new (readall = 0)
Examples readall = 1
readall = 0
Maximum message size to retrieve
Function Specify a maximum message size to retrieve. Messages larger than this will be left on the server and not retrieved.
Syntax max_message_size = value (bytes)
Optional Yes
Default 0 (No limit)
Commandline equivalent None
Examples max_message_size = 2000000
max_message_size = 150000
Maximum message size to retrieve
Function Specify a maximum message size to retrieve. Messages larger than this will be left on the server and not retrieved.
Syntax max_message_size = value (bytes)
Optional Yes
Default 0 (No limit)
Commandline equivalent None
Examples max_message_size = 2000000
max_message_size = 150000
Delete messages from server after retrieval
Function Delete messages from the POP3 server after retrieval.
Syntax delete = bool
Optional Yes
Default 0 (Do not delete)
Commandline equivalent --dont-delete (delete = 0)
--delete (delete = 1)
Examples delete = 1
delete = 0
Delete messages X days after retrieval
Function Delete messages a specified number of days after they are first retrieved.

Note: delete overrides delete_after.
Syntax delete_after = value (days)
Optional Yes
Default 0 (Do not use delete_after)
Commandline equivalent None
Examples delete_after = 3
delete_after = 180
getmail Behaviour

The following directives are specified in any getmailrc section, and are used to control other aspects of getmail's behaviour.

Verbosity
Function Specify whether getmail writes status and informational messages to stdout while running.
Syntax verbose = bool
Optional Yes
Default 1 (Verbose)
Commandline equivalent --verbose (verbose = 1)
--quiet (verbose = 0)
Examples verbose = 1
verbose = 0
Message Logging
Function Specify whether getmail writes message retrieval and delivery information to a log file. Set to the empty string to disable logging. This value is expanded for leading "~" or "~user".
Syntax message_log = file
Optional Yes
Default None
Commandline equivalent None
Examples message_log = /var/log/getmail
message_log = ""

Running getmail

Run the getmail helper script you installed earlier:

getmail

By default, getmail will read in the default getmailrc file ($HOME/.getmail/getmailrc) and begin retrieving mail.

You can also supply commandline options. For a brief summary of usage and commandline options, run:

getmail --help

getmail Commandline Options

getmail understands the following commandline options:

Long FormShort FormSummary
--help-hDisplay usage and default option values and exit
--getmaildir path-g pathUse path as getmail configuration/data directory
--rcfile file-r fileUse file as getmailrc configuration file
--quiet-qNo status output
--verbose-vVerbose status output
--message-log file-m fileLog getmail operations to file
--all-aRetrieve all messages
--new-nRetrieve only new messages
--delete-dDelete messages after retrieval
--dont-delete-lDo not delete messages after retrieval
--timeout val-t valSet socket timeout to val seconds
--traceEnable debugging output
--dumpDump configuration and exit
--help or -h
Long Option --help
Short Option -h
getmailrc equivalent None
Function Display usage information, then exit.
--getmaildir or -g
Long Option --getmaildir path
Short Option -g path
getmailrc equivalent None
Function Use path as getmail configuration/data directory. Defaults to $HOME/.getmail/
--rcfile or -r
Long Option --rcfile filename
Short Option -r filename
getmailrc equivalent None
Function Use filename as getmailrc file. Defaults to getmailrc in the getmaildir directory.
--quiet or -q
Long Option --quiet
Short Option -q
getmailrc equivalent verbose = 0
Function Produce output only on error.
--verbose or -v
Long Option --verbose
Short Option -v
getmailrc equivalent verbose = 1
Function Write status and progress messages to stdout.
--message-log
Long Option --message-log file
Short Option None
getmailrc equivalent message_log = file
Function Log message retrieval and delivery information to file.
--all or -a
Long Option --all
Short Option -a
getmailrc equivalent readall = 1
Function Retrieve all messages.
--new or -n
Long Option --new
Short Option -n
getmailrc equivalent readall = 0
Function Retrieve only previously unseen messages.
--delete or -d
Long Option --delete
Short Option -d
getmailrc equivalent delete = 1
Function Delete messages from server after retrieval.
--dont-delete or -l
Long Option --dont-delete
Short Option -l
getmailrc equivalent delete = 0
Function Leave messages on server after retrieval.
--timeout or -t
Long Option --timeout value (seconds)
Short Option -t value (seconds)
getmailrc equivalent timeout = value (seconds)
Function Set TCP timeout to value seconds.
--trace
Long Option --trace
Short Option None
getmailrc equivalent None
Function Write verbose debugging information to stdout.
--dump
Long Option --dump
Short Option None
getmailrc equivalent None
Function Do not retrieve mail; read getmailrc file and commandline options, then print configuration on stdout. This information should be included in all bug reports or support requests.