11.06-Fetchmail
Description: FreeBSD Installer Guide-Fetchmail
Keywords: Fetchmail, fetchmail, commands

# FreeBSD Stable Release 6.0 Installer Guide

______________________________________________________________________

# Fetchmail Port / Getting Your ISP Email To FBSD

To get email that is stored in your ISP mailbox waiting to be picked up and delivered to your user on your local FBSD box, you have to install another FBSD application. Fetchmail is a full-featured, robust, remote-mail retrieval and forwarding utility intended to be used over on-demand TCP/IP PPP connections. It supports every remote-mail protocol now in use on the Internet: POP2, POP3, RPOP, APOP, KPOP, all flavors of IMAP, ETRN, and ODMR. It can even support IPv6 and IPSEC. It may also be useful as a message transfer agent for ISP sites which refuse for security reasons to permit (sender-initiated) SMTP transactions for collecting email.

For the Fetchmail Reference Manual see

http://www.catb.org/~esr/fetchmail/fetchmail-man.html

The home page is at

http://www.catb.org/~esr/fetchmail/

Fetchmail is commonly used to access your ISP email account using the pop3 protocol by logging into your ISP email server as you, retrieving the email, and delivering it to SMTP port 25 where the FBSD sendmail server is listening. Sendmail does not know the difference between this method or receiving public inbound email directed by a domain name, because in both cases email just shows up at its front door.

The fetchmail program is command line driven. By this I mean you can manually enter the fetchmail command on the FBSD command line any time you want get your email from your ISP account. It has a alternate mode of operation where you can tell it to start as a daemon to keep running and check email on a timed cycle. This is the customary way users configure it to function. You are going to put fetchmail in the root directory to make the startup of fetchmail at boot time. This is simple to accomplish during the manual configuration of fetchmail.

# Fetchmail Installation Instructions

pkg_add –rv fetchmail

rehash

After the package is installed, you are ready to manually create fetchmail's run time options file in the home directory of user root.

cd /root/

ee .fetchmailrc

set postmaster root
set no bouncemail
set no spambounce
# Example of fetching email from individual ISP email accounts and
# populating their sendmail server mailboxes.
# user statements show use of added readability words.
# Of course each ISP account has its own password.
poll mail.manbay.net, protocol pop3, no dns
user dadisp there with password xxxxxx is dadfbsd here
user momisp there with password xxxxxx is momfbsd here
user tomisp there with password xxxxxx is tomfbsd here
user bobisp there with password xxxxxx is bobfbsd here
# Example of fetching email from a multi-drop ISP account and
# populating the users sendmail server mailboxes.
# multi-drop means all the email for all of the users of registered
# domain name is forwarded to a single ISP account.
#
# If you are not doing this then delete this example.
# The poll statement option localdomains must be followed by the
# domain name sendmail thinks it's responsible for.
# From rc.conf hostname= statement.
#poll mail.manbay.net, proto pop3, no dns,
# envelope Envelope-To, localdomains yourdomainname.com,
# user dad0 there with password xxxxxx is * here
#
###################### End of File #####################################

postmaster is the account name of the user who will be the last-resort email recipient. root is a valid entry; It can be any user you want.

bouncemail & spambounce logical happened at the ISP so anything that fetchmail/sendmail thinks is wrong is really wrong, so 'no' means direct error email to postmaster.

The poll statement is the main control statement for specifying your target ISP and providing the account information to login and how your email is to be handled by fetchmail as it hands it off to sendmail.

Replace mail.manbay.com with the name of your ISP pop3 email server.

Replace tomisp with the account name of your ISP email account that you want to retrieve the email from.

Replace xxxxxx with the password of the ISP tomisp account.

Replace tomfbsd with the account name on FBSD you want the retrieved email put into. This is the account on the FBSD box where fetchmail will deposit the email it gets from your ISP.

For each ISP account that you want to retrieve email for and populate the user’s sendmail mailbox, just add another user statement following the same syntax.

Installer Note:

The FBSD account names you substituted for "tomfbsd" have to be created by adduser or pw before you use fetchmail.

For security concerns you have to change the /root/.fetchmailrc file permissions to 600 (u=rw,g=,o=), on the command line enter:

chmod 600 /root/.fetchmailrc

In daemon mode there are no error messages coming out on the screen. They are going to the syslog facility named mail. The mail facility is also used by sendmail. The message level of mail.info posts an entry in the log for every time fetchmail is executed, which is every 5 minuets in daemon mode. This just fills up the log file with useless information. To correct this problem syslog.conf has to be updated. Change the mail.info statement so it look like this.

ee /etc/syslog.conf

mail.notice /var/log/maillog

To activate the changes to /etc/syslog.conf you can reboot or bump the syslog task into re-reading /etc/syslog.conf by kill –HUP pid. You get the pid (IE: process number) by listing the tasks with the ps ax command. Find syslogd in the display and its pid is the number in the left column.

Set up fetchmail to automatically start up in daemon mode at boot time.

Create a script to start fetchmail at boot time.

ee /usr/local/etc/rc.d/fetchmail.sh

#! /bin/sh
fetchmail -d 300 --syslog

The -d 300 option says run fetchmail in daemon mode checking email every 5 minutes.

The 300 value is 5 minutes in seconds. You can change the interval to what ever you want, just as long you specify it in seconds.

The --syslog tells fetchmail to use the syslog facility.

The permission on this script file must be read, write, exec for owner root.

chmod 700 /usr/local/etc/rc.d/fetchmail.sh

# Testing Fetchmail

You are now ready to perform your first test of fetchmail. On the command line enter:

fetchmail -v -c

The -v option creates verbose messages.

The -c option means just check my ISP email account and tell me how many emails are there. At this point you just want to see if you can log in to your ISP account.

Here is what the results should look like

fetchmail: 6.2.4 querying mail.manbay.com (protocol POP3) at Fri Mar 8
00:18:12 2002: poll started
fetchmail: POP3< +OK mail.manbay.com POP3 server (Post.Office v3.5.3 release
223 with ZPOP version 1.0 ID# 0-52377U2500L250S0V35) ready Fri, 8 Jan 2004
00:22:35 -0500
fetchmail: POP3> USER tomisp
fetchmail: POP3< +OK Password required for tomisp
fetchmail: POP3> PASS *
fetchmail: POP3< +OK Maildrop has 1 messages (6287 octets)
fetchmail: POP3> STAT
fetchmail: POP3< +OK 1 6287
fetchmail: POP3> LAST
fetchmail: POP3< +OK 0
1 message for tomisp at mail.manbay.com (6287 octets).
fetchmail: POP3> QUIT
fetchmail: POP3< +OK mail.manbay.com POP3 server closing connection
fetchmail: 6.2.4 querying mail.manbay.com (protocol POP3) at Fri Jan 8
00:18:16 2004: poll completed
fetchmail: normal termination, status 0

The above results will vary depending on what pop3 server software your ISP is using. If you did not receive something close to this you have problems. The last line status 0 is a return code. Status 1 means no mail to retrieve. See the fetchmail manual for the meanings of each status return code. The most common error here is you have an incorrect name for your ISP pop3 email server. If you are having problems logging in, call your ISP to verify your email account name and password and the email server name.

# Fetchmail Commands

Enter on the command line one of these:

start daemon = fetchmail -d 300 --syslog

stop = fetchmail -q

start non-daemon = fetchmail -v

start check mail = fetchmail -v –c

______________________________________________________________________

This FreeBSD Installer Guide is an public domain HOW-TO. This content may be reproduced, in any form or by any means, and used by all without permission in writing from the author.