Fetchmail

Updated: May 07, 2024

As you already know from by previous Postfix (with smtp.gmail.com as relayhost) article, Any mail going through drunkenmonk.org domain will have my gmail address as sender. Thats good. What about receiving mail from gmail?

In your mind, you are saying Its damn easy right? configure your evolution/thunderbird to poing to gmail stupid? right? yeah, thats right. I can configure any mail client to point to gmail and get mails. But, I want my postfix to play a roll.

Postfix is basically a smtp server, it can also act like smtp client. But, it cant work as a imap/pop3 client.

So, Here is the task, I need to get mails from gmail through pop3 and put it into my postfix so that all other clients connected with my postfix can get that mail. Here comes fetchmail.

../../_images/bighand.png

Fetchmail is a beautiful program which will act like imap/pop3 client (just like evolution/thunderbird) and instead of saving it somewhere, fetchmail will put that mail into your local machine’s mail server. So, all the mail clients connected with your local mail server will get your email from gmail.

Thats enough of theory, lets get down and install fetchmail, first install the package

$ sudo equo install fetchmail
$

Now time to configure fetchmail, it uses /etc/fetchmailrc as its only configuration file. But, we need to be careful with it. Because, we are saving the username/password a plain-text, so the permission for /etc/fetchmail should be (0600) for root.

If you start configuring fetchmail by reading man fetchmail, you will switchoff easily. That man page is such a damn brief and will confuse you easily. But, fetchmail config is really a easy one. It will take just three lines to configure it. Here is those three lines,

set daemon 120
set syslog
poll pop.gmail.com proto pop3 user "foo" pass "bar" to "stupid" ssl sslproto "TLS1"

Here, set daemon 120 will make fetchmail to connect to gmail server every 2 minutes. set syslog will make fetchmail to put logs into syslog. poll pop.gmail.com instructs fetchmail to connect to pop.gmail.com server. proto pop3 instructs fetchmail to use pop3 protocol. user 'foo' pass 'bar' to 'stupid' instructs fetchmail to use foo as username and bar as password to open gmail account in gmail server, fetch those mail from gmail server and put it into local machine’s postfix as a mail for stupid user. ssl instructs fetchmail to use secure connection. sslproto 'TLS1' tells fetchmail to use STARTTLS for sercure connection.

Thats it for configuration stuff, now its time to restart fetchmail

$ sudo eselect rc restart fetchmail
$

Now, you can see your mails are fetched from gmail and available to you through mailx command.