Retrieving Mail with POP3 and IMAP

 < Free Open Study > 



Although POP and IMAP are usually used by MUAs for accessing user's mailboxes remotely, they're also used to "pull" mail from a server for local redelivery. Two utilities, Fetchmail and getmail, are commonly used on qmail systems.

Using Fetchmail

Fetchmail is a program that retrieves mail from a POP or IMAP server and reinjects it locally. More information about Fetchmail is available on the Web (http://www.tuxedo.org/~esr/fetchmail/). Fetchmail has no trouble retrieving mail from qmail servers, but there are a couple tricks for making it work well on a qmail client.

Fetchmail is configured via the .fetchmailrc file in a user's home directory. Each stanza in the .fetchmailrc file tells fetchmail how to retrieve mail from a remote mailbox and reinject it for local delivery.

Here's a sample .fetchmailrc for a user on a qmail system:

 poll mail.example.net proto pop3 nodns     user dsill with password flubgart is dave here     fetchall forcecr 

The first line instructs fetchmail to connect to mail.example.net via POP3. The nodns tells fetchmail not to perform a DNS lookup on the envelope sender domain of messages retrieved from this server. The second line tells it to log in as user dsill with password flubgart and that the local recipient of the messages is user dave. The third line tells it to retrieve all of the messages (fetchall) and to force all lines to be terminated by carriage return/linefeed, as SMTP requires (forcecr). The forcecr option is required with qmail when fetchmail is configured to reinject messages via SMTP, which is the default.

Fetchmail can also be configured to reinject messages using qmail-inject. For example:

 poll mail.example.net proto pop3 nodns     user dsill with password flubgart is dave here     fetchall mda "/var/qmail/bin/qmail-inject dave" 

Here, the mda keyword is used to tell fetchmail how to invoke a local Message Delivery Agent (MDA); in this case, the command used is /var/qmail/bin/qmail-inject dave.

Using Fetchmail with Domain Mailboxes

Fetchmail includes support for qmail virtual domains. A mailbox on a qmail system can accumulate mail for an entire virtual domain, and fetchmail on another qmail system can retrieve that mailbox and automatically redeliver the messages to multiple local addresses.

For example, say virtual.example.com is a virtual domain hosted by an Internet service provider (ISP), isp.example.net, and the virtual domain is managed by user mjsill. The virtualdomains entry on isp.example.net would look something like this:

 virtual.example.com:mjsill-virtual 

User mjsill creates a .qmail-virtual-default file that causes all mail to the virtual domain to be delivered to her POP mailbox.

On her local qmail system, user maryjane creates a .fetchmailrc file containing this:

 poll isp.example.com proto pop3 nodns     qvirtual "mjsill-virtual-"     user mjsill with password gartflub     fetchall forcecr     to * here 

The qvirtual keyword specifies a virtual domain prefix to be stripped from the local part of address in the first Delivered-To header field, which becomes the recipient on the local system. So if a message was originally sent to <info@virtual.example.com>, it would have a Delivered-To header field of this:

 Delivered-To: mjsill-virtual-info@virtual.example.com 

Fetchmail, on receiving the message, would take the local part of the address, mjsill-virtual-info, remove the prefix specified with the qvirtual keyword, mjsill-virtual-, and reinject the message to info@localhost.

Using getmail

getmail is a program that retrieves mail from a POP server and delivers it to a maildir mailbox, mbox mailbox, or a command. It's written in the Python language, so you may need to install the Python interpreter before you can use getmail.

getmail was created by Charles Cazabon, who maintains a Web page for it (http://www.qcc.sk.ca/~charlesc/software/getmail-2.0/getmail.html).

Installing getmail

If you've got Python version 1.5.2 or later, you should be able to install getmail. If you don't have Python, it's available from the Web (http://www.python/org/). To install it, follow these steps:

  1. Download the getmail tarball using your Web browser or a commandline utility. At the time of this writing, the current version is 2.1.3. For example, using the wget utility, do this:

     $ wget http://www.qcc.sk.ca/~charlesc/software/getmail-2.0/getmail-2.1.3.tar.gz --11:25:57--  http://www.qcc.sk.ca/%7Echarlesc/software/getmail-2.0/getmail-2.1.3 .tar.gz             => 'getmail-2.1.3.tar.gz' Connecting to www.qcc.sk.ca:80. . . connected! HTTP request sent, awaiting response. . . 200 OK Length: 39,447 [application/x-gunzip]     0K ->  ......................................                               [100%] 11:26:13 (2.71 KB/s) - 'getmail-2.1.3.tar.gz' saved [39447/39447] $ 

  2. Unpack the tarball:

     $ gunzip getmail-2.1.3.tar.gz $ tar xf getmail-2.1.3.tar $ 

  3. Copy the getmail files to their installed locations. We'll copy everything to /usr/local/lib/getmail and install the getmail program in a directory in user's executable paths, such as /usr/local/bin:

     $ su root Password: rootpassword # mkdir /usr/local/lib/getmail # cp -a getmail-2.1.3/* /usr/local/lib/getmail # cp -a getmail-2.1.3/getmail /usr/local/bin # chmod 755 /usr/local/bin/getmail # exit $ 

Configuring getmail

getmail is configured via $HOME/.getmail/getmailrc. The format of the getmailrc is similar to that used in many Windows configuration files, with sections labeled in square brackets ([]) and settings in this format:

 variable = value 

The [default] section contains settings that act as defaults for the remaining sections. Each named section tells getmail how to retrieve one remote POP3 mailbox. For example, a simple getmailrc might look like this:

 [default] verbose = 1 readall = 0 delete = 1 [Example] server = dolphin.example.com username=jheiskell password=Judyb4ts postmaster = ~/Maildir/ 

The [default] section tells getmail to be verbose, read all messages, and delete them from the POP3 mailbox after delivering them locally.

The [Example] section tells getmail to log into dolphin.example.com as user jheiskell with the password Judyb4ts and to deliver the messages retrieved to $HOME/Maildir/, which is a maildir mailbox because it ends with a slash (/).

Running getmail

With $HOME/.getmail/getmailrc in place, run getmail to retrieve your messages. For example:

 $ getmail getmail v.2.1.3 - POP3 mail retriever with reliable Maildir and mbox delivery.   (ConfParser version 2.0) (timeoutsocket version 1.12) Copyright (C) 2001 Charles Cazabon <getmail @ discworld.dyndns.org> Licensed under the GNU General Public License version 2. See the file COPYING for details. dolphin.example.com:  POP3 session initiated on port 110 for "jheiskell" dolphin.example.com:  POP3 greeting:  +OK <25418.997637290@dolphin.example.com> dolphin.example.com:  POP3 user response:  +OK dolphin.example.com:  POP3 PASS response:  +OK dolphin.example.com:  POP3 list response:  +OK   msg #1 : len 1885 . . . retrieved . . . delivered to postmaster ... deleted dolphin.example.com:  finished retrieving messages dolphin.example.com:  POP3 session completed for "jheiskell" dolphin.example.com:  retrieved 1 messages for 1 local recipients $ 

Using getmail with Domain Mailboxes

Like Fetchmail, getmail includes support for virtual domains. A mailbox on a POP server can accumulate mail for an entire virtual domain, and getmail can retrieve that mail and automatically redeliver the messages to multiple local addresses.

Using the same example we used for Fetchmail, say virtual.example.com is a virtual domain hosted by an ISP, isp.example.net, and the virtual domain is managed by user mjsill.

On her local qmail system, user maryjane creates a getmailrc file containing this:

 server = dolphin.example.com username=mjsill password=gartflub postmaster = ~/Maildir/ local = sales@virtual.example.com,~/virtual/jason/Maildir/ local = ceo@virtual.example.com,~/virtual/lynette/Maildir/ 

The two local settings will cause getmail to deliver mail addressed to the associated addresses to the local virtual mailbox of the intended recipient.

Note 

getmail must be able to write to the mailboxes to which it delivers. If these mailboxes belong to different Unix user IDs (UIDs), you'll have to make them writable by the group under which getmail runs.



 < Free Open Study > 



The Qmail Handbook
The qmail Handbook
ISBN: 1893115402
EAN: 2147483647
Year: 2001
Pages: 186
Authors: Dave Sill

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net