Originally Published: Thursday, 27 September 2001 Author: Michael & Melinda Petruzziello
Published to: learn_articles_firststep/General Page: 2/3 - [Printable]

Beginner's Week: Notes from the Command-Line Commando: Fetchmail

In this, the first of a series of articles dedicated authors Michael and Melinda Petruzziello try a unique writing style to convey everything you need to know to start being a command line commando. It's fun writing and useful stuff on setting up fetchmail. Read on!

Fetchmail Setup  << Page 2 of 3  >>

Finally: Fetchmail

Now that you've read about my computer experience and my Linux box, it's time to get to the meat of this article: fetchmail, for personal use.

One of the first things I wanted to do when I first set up my Linux box was send and receive email. To read my email, I use Pine v4.21 (which I think is the latest version at this time). Sending and receiving email to users on the system or in a network environment is easy with Pine, but what if you want to receive email from a source outside your network? Fetchmail is the answer.

First Things First

Make sure you have your Linux box set up for email support. You will need to have at least three email utilities installed:
  • sendmail, the MDA (mail delivery agent)
  • fetchmail, for retrieving email from sources outside your network
  • pine, for reading and composing your email

    When I installed RedHat 6.2, I selected these utilities as part of my install. If you did not install these utilities during setup and you use RedHat, install them from the RPMs included on your installation CD. If you don't have a CD or if you are using a different version of Linux, then you may have to get these files from the web. If you are not sure if these packages are installed, try the following:

    login: <username>
    Password: *******

    $ rpm -q sendmail <Enter>

    You should see something like the following, if sendmail is installed:


    or you might see:

    package sendmail is not installed

    If the reply comes back "package not installed," then obviously the package needs to be installed. Follow these steps to make sure fetchmail and pine are installed also, and then take the appropriate action necessary. Again, I am a RedHat guy, so this may vary on your system.

    All right! I got everything; let's get on with it!

    Sendmail Setup

    This section is very brief. If sendmail is installed properly on your system, then its default settings should work just fine. If not (ahhhhh!), check the various HOW-TO sites on the web. This I know, however; RedHat's default sendmail installation works peachy (gratuitous RedHat plug -- thank me later, Mr. Young).

    All right, now that sendmail is setup, let's go on to pine.

    Pine Setup

    Here, we come to the easy part. Login and start pine. On the initial screen, arrow down to Setup and press <Enter>. You will see a menu at the bottom of the screen; press <C>. You will then see another menu. The top three options are the ones we need to check:

    - The top one is "personal-name." Highlight it by using the arrow keys and press <C>. This will allow you to change the information there. Type in your name, if it's not there already, and press <Enter>.

    - The next one on the list is "user-domain". Highlight it and press <C>. Type in the last part of your email address after the @ symbol and then press <Enter>. For example, if your email address is "frank@mail.server.com," you put "mail.server.com."

    - The next one is "smtp-server". Highlight this, press <C>, type in your SMTP (or outgoing mail) server name, and press <Enter>.

    Press <E> to exit Setup. Pine will ask if you want to save changes; type <Y>for yes, and you will find yourself back at the main menu. Press <Q> to quit pine.

    Fetchmail Setup

    Fetchmail is a very powerful program and can handle various email-related tasks. For example, I use fetchmail to handle all the email of a major client of mine. Fetchmail goes out, grabs the mail, and then separates it (this involves a script) into individual mailboxes for each user. Employees login individually with a POP3 email client and get their mail. However, since this article is focused on how to use fetchmail for your personal email, I will be leaving most of the beefy stuff out for now.

    Before you configure fetchmail, I recommend that you have a username that is the same as your email login name. For example, if your email address is "frank@mail.server.com," setup a username of "frank." I highly recommend doing this because it keeps the confusion down. (As we go through this example, you will see what I mean.)

    OK, time to set things up. Let's start by logging in with the username you will be using to receive the email (NOT as root). Now, there is more than one way to invoke fetchmail. If you type:

    fetchmail mail.server.com <Enter>

    at the command prompt, fetchmail will prompt you for a password, and then check for email (IMAP and POP3) at the server mail.server.com with whatever username you happen to be logged in with. For example, if you are logged in as "frank," it will check frank@mail.server.com. If your email name is not the same as your username, don't give up hope. If you are logged in as "frank," but your email address is "franklin@mail.server.com," you can type this instead:

    fetchmail -u franklin mail.server.com <Enter>

    Then, fetchmail will contact mail.server.com using the IMAP and POP3 protocols, and try to login as "franklin." You will then be prompted for your password. Type it in, press <Enter>, and presto! You've Got Mail! (Ahhhh! Did I say that? Sorry!)

    Let's say you're tired of fetchmail checking both the IMAP and POP3 protocols, because you only have a POP3 account. To get rid of the IMAP error message you keep seeing, type:

    fetchmail -p pop3 mail.server.com <Enter>

    And, if your username is different than your login name, type:

    fetchmail -p pop3 -u username mail.server.com <Enter>

    You will then see a prompt for your password. Again, type it in, etc., etc., ad nauseam.

    Now, if you're like me, you're not going to want to type all this information in every single time you want to check your mail. And so, we come to the subject of the .fetchmailrc file. Once you have a .fetchmailrc file setup properly, you can just type:

    fetchmail <Enter>

    at the prompt.

  • Fetchmail Setup  << Page 2 of 3  >>