Mail - retrieving
From NewbieDOC
- Andrei Popescu
- andreimpopescu at gmail dot com (author)
- Chris Lale
- chrislale AT users DOT berlios DOT de (publisher)
Go to NewbieDOC index
Revision History
Revision 1.0 | 14th July 2007 | Revised by Andrei Popescu | ||||||||||||||
Initial release. | ||||||||||||||||
| ||||||||||||||||
Revision 1.1 | 27th November 2007 | Revised by Andrei Popescu | ||||||||||||||
Reformatted for newbiedoc package. Added Revision History, Abstract and License in Appendix. | ||||||||||||||||
Help for Debian newbies wnting to retrieve mail from a POP account using Getmail.
1 IntroductionThere are many ways to retrieve mail on a Debian GNU/Linux system. Most graphical and even some non-graphical mail clients, also known as MUA (Mail User Agent) can do this. The method I describe below has the big advantage that it does not depend on any MUA. This way you can still receive mail even if your graphical mail client (or whole X) is broken for some reason. (This is almost unheard of with the stable distribution, but can happen if you run unstable). 2 Basic SetupThe best known program for this task is fetchmail. While fetchmail can do a lot of things it is not very easy to setup. For this reason I choose getmail. We need to install it first and need to be root for that: # aptitude install getmail4 There is also a getmail package, but it is unmaintained and you shouldn't use it. After completing the installation you can (and should) continue your work from your normal account. First we need to create a directory for getmail's files. The standard location is in your own home directory (Note: I will asume you work from your homedir. If this is not the case then you must prepend something like "~/" to all paths): $ mkdir .getmail We also need to create a storage for the mail. A good option is the Maildir format, as it allows different programs to access the storage at the same time (as opposed to mbox). The best way would be to create this using your mail client. If the default storage of your client is not Maildir just look for the "new mailbox" or similar option. Some clients also need a separate plugin in order to use Maildir style storage. The Maildir should best be created in your homedir. Make sure you know the name of the directory as you will need it. I will assume it is 'Maildir'. Another way to create maildirs is to use the program 'maildirmake' from the maildrop package. 3 getmailrc - getmail's configuration fileIn order to use getmail we need to tell it some information about our mail account. This goes to the getmailrc file. You will need to create one for each account you want to retrieve mail from. For the moment we will create just one (replace 'mcedit' with your prefered editor): $ mcedit .getmail/getmailrc For a typical POP3 account you will need to add something like the following (lines starting with # are just comments): [retriever] type = SimplePOP3Retriever server = pop.example.com username = your_username password = your_password [destination] type = Maildir path = ~/Maildir/ [options] # we don't want to retrieve the same messages at each run # remove the # from the next line *after* you are sure everything is setup ok #read_all = False # delete messages from the server 3 days after retrieving them # or use 'delete = true' instead # remove the # from the next line *after* you are sure everything is setup ok #delete_after = 3 As you can see, the two options are commented out. This is done to prevent loss of mail in the configuration phase. After everything is setup ok you should uncomment them. We also need to make this file unreadable by other users on the system because it contains the password in clear text: $ chmod 600 .getmail/getmailrc We can test the configuration by invoking getmail with no arguments. The result should look like the following: ~$ getmail getmail version 4.6.5 Copyright (C) 1998-2006 Charles Cazabon. Licensed under the GNU GPL version 2. SimplePOP3Retriever:your_username@pop.example.com:110: msg 1/1 (3622 bytes) delivered 1 messages retrieved, 0 skipped Getmail retrieved the message number 1 from a total of 1. Use your mail client to read the mail. You might need to tell it to refresh folders to see the new mail (pressing the Receive/Get Mail button might be enough). If you have many messages waiting on your server you should interrupt getmail after retrieving a couple of them by using Ctrl C if you don't want all messages retrieved many times. This is only needed in the test phase, because later we will enable the necessary options in getmailrc. If the test was ok then we need some final steps. 4 Finishing touchObviously, we should first enable the two options in getmailrc to prevent duplicate messages. If you don't want to run getmail occasionaly (by invoking it from commandline) there is one more thing to do. Following unix philosophy, getmail does not include the possibility to run automaticaly at specified intervals, but relies on cron for that. Cron should already be installed and running on your system, so all you need is to setup a "crontab". Crontabs are just text files in a special location, but you should only create/edit them with the following command: $ crontab -e Depending on how your system is setup, the editor vi might be the one used. If this is not what you want (type ":q" whitout the quotes and press Enter to exit vi) then use the following (replace 'mcedit' with your prefered editor, of course): $ EDITOR=mcedit crontab -e For an interval of 10 minutes, your crontab should look like this: # m h dom mon dow command 0-59/10 * * * * /usr/bin/getmail --quiet 5 Appendix A: LicenseCopyright (c)2007 Andrei Popescu, andreimpopescu at gmail dot com
Go to NewbieDOC index |