Friday, August 24, 2007

retrieve GMail emails via terminal using fetchmail

This entry will cover a one shot linux fetchmail command of retrieving GMail email messages using terminal without any further fetchmail configuration setup. Read on.

Fetchmail is one good linux tool for fetching and retrieving remote emails. Fetchmail works and retrieves emails from remote email servers and downloads them locally into your local linux box.

I agree that there are a lot of MUAs or email retrieval softwares available both from windows and linux world. If you wish to configure other mail retrieval softwares to retrieve emails from your GMail account, you can visit and read more from here.

Make sure your GMail account to allow POP3 retrieval from external source. If not, this can be with the below instructions.

Login into your GMail account. From there, click Settings from the right corner of your screen. Click Forwarding and POP from one of the tabbed menus and select Enable POP for all mail. From here, you have an option to keep a local copy of emails retrieved or delete the original copy when retrieved by external mail user agent. Click Save to make your changes permanent.

This entry would be accomplished without launching fetchmail in daemon service mode and/or without further configuration to fetchmail default .fetchmailrc configuration file. This entry also assumes that

1. fetchmail package is currently installed from current local box. If not, simply install fetchmail as follows:

# yum -y install fetchmail

2. sendmail, exim, qmail, postfix or any mail transfer agent (MTA) is currently installed and currently running from local box. If not, any mail delivery agent (MDA) like procmail, maildrop or deliver is currently available from local box. Proper configuration of these mentioned package would not be covered here though.

How to retrieve emails from GMail account using fetchmail via terminal?

If you issue the below command as root, the retrieved emails would automatically be dropped or delivered to root mail box. Also prepare your GMail password upon executing the below command.

# fetchmail -v -k -u YOU@gmail.com --ssl -P 995 pop.gmail.com -m "/usr/sbin/sendmail -i -f %F -- %T"

LEGEND:
-v for more verbose fetchmail settings
-k keeps and retains email copies from GMail
-P followed by GMail POP3s port number and POP host server
-m mail would be delivered by sendmail

Any non-zero returned exit status means failure.

You've Got Mail!

Fetchmail can do this GMail mail retrieval steps in various ways. The above is only one way to do it.

Here's another one-shot alternative way to retrieve GMail using fetchmail from terminal.

This time around, it is assumed that any mail transfer agent (MTA) like sendmail, exim or postfix is currently NOT installed. Fetchmail can deliver mails using other MDAs like procmail as an example.

Again, this is possible in one shot fetcmail command without further fetchmail configuration setup and procmail setup.

Here's how to fetch Gmail email using fetchmail and procmail. Simply do as follows:

# fetchmail -v -k -u YOU@gmail.com --ssl -P 995 pop.gmail.com -m "/usr/bin/procmail $h $g"

You've got mail again!

0 comments:

Sign up for PayPal and start accepting credit card payments instantly.
ILoveTux - howtos and news | About | Contact | TOS | Policy