Automatically Label Mail in Gmail with POPFile

Woman working at computer in office.

Klaus Vedfelt / Getty Images


Labels are nice for organizing a few messages in Gmail, or for having Gmail organize incoming mail for you using filters.

Using POPFile in conjunction with Gmail, you can have trainable labels: if you label a message, the system learns and automatically assigns the same label to similar messages in the future. To correct a labeling error, you just apply the correct one or move the message to your Gmail inbox.

Automatically Label Mail in Gmail with POPFile

To have POPFile apply labels to messages in Gmail automatically based on what you're teaching it to do:

  • Make sure POPFile's IMAP and SSL modules are installed.
    • The POPFile installer lists them as optional modules, not checked by default; select them during installation.
  • Open the POPFile user interface in your browser.
  • Define buckets corresponding to the Gmail labels you want POPFile to apply automatically.
    • The POPFile buckets do not have to be named identically to their Gmail label counterparts.
  • Go to the Advanced tab.
  • Enter "1" (not including the quotation marks) under imap_enabled (set to "0", i.e. off, by default).
  • Click Update.
  • Follow the Shutdown POPFile at the top.
  • Restart POPFile.
  • Open the POPFile interface again.
  • Go to the Configuration tab.
  • Enter "" (excluding the quotation marks) under IMAP server hostname:
  • Type "993" under IMAP Server port.
  • Make sure Use SSL is checked.
  • Type your Gmail username under IMAP account login.
  • Enter your Gmail password under Password for IMAP account.
  • Click Apply.
  • Now click now under Refresh list of folders.
  • Select INBOX under Watched folder no1 to classify incoming emails with POPFile by default.
  • Choose the appropriate Gmail folders (i.e. labels) for the POPFile buckets.
    • Pick the INBOX folder for the bucket 'unclassified'.
    • If you have a "spam" bucket, map it to the [Gmail]/Spam. We would not necessarily filter spam with POPFile for Gmail, though; it adds a little bit of work for your processor and network.
  • Click Apply.
  • Follow the Shutdown POPFile at the top.
  • Restart POPFile.

Note that a label automatically applied by POPFile removes the message from Gmail's default Inbox.

Train POPFile to Apply Gmail Labels Automatically

You can train POPFile to label your mail correctly by applying and removing labels in Gmail:

  • If POPFile has applied the wrong label or no label at all where you wanted one:
    • Apply the desired label in Gmail and remove the unwanted.
  • If POPFile has labeled a message you wanted to appear in the Gmail Inbox unlabeled:
    • Select Move to inbox from Gmail's More Actions menu.
    • Remove the unwanted label.
  • If Gmail has missed a spam email:
    • Use Gmail's Report Spam button or press !.