Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve and parse emails from (POP3 or IMAP) mailbox in Symfony2

Tags:

php

email

symfony

I am looking for a package/bundle that can access an email inbox, retrieve the emails in the inbox and parse them (Sender Email, Subject, Body, Attachments) for processing in my Symfony2 application. The idea is a "helpdesk" where people can email a specific email address and a cron job will run through the email inbox and convert emails into helpdesk tickets (with attachments).

Before anyone tells me to Google or something equally unhelpful, please note that I have spent over an hour on Google as well as gone over more than 100 StackOverflow threads looking for something that can help me with this. Most of the content involves sending emails and not retrieving them. I have built a pure PHP parser before and it was a nightmare (as almost every email client composes the emails a little differently).

I found https://packagist.org/packages/lasso/mail-parser-bundle, but it seems to only be for Zend. I have also found https://github.com/iJanki/MailMimeDecodeBundle, but it seems to still be a work in progress and there is no documentation to speak of. Additionally, I found Correct way to retrieve mails by IMAP in symfony2, but that looks just like the start of the nightmare I had last time when I built one from scratch.

I would appreciate any suggestions or pointers from anyone who has implemented something similar or has been in a similar situation.

like image 971
Magnanimity Avatar asked Jul 08 '14 08:07

Magnanimity


People also ask

What is a POP3 mail server?

The POP3 (P ost O ffice P rotocol Version 3) is an application-layer Internet standard protocol used by local Email clients to retrieve Email from a remote server over a TCP/IP connection. This tutorial shows how to connect to POP3 mail server and manage incoming Email using the ‘telnet’ command.

How to use eagetmail POP3&IMAP component in your project?

To use EAGetMail POP3 & IMAP Component in your project, the first step is “Add reference of EAGetMail to your project”.

How do I Find my POP3 server?

For example, you can choose menu -> Tools -> Accounts -> Your email account -> Properties -> Servers in Outlook express or Windows Mail to get your POP3 server, user. Using EAGetMail to receive email does not require you have email client installed on your machine or MAPI, however you can query your exist email accounts in your email client.


1 Answers

I have found a PHP class that does exactly what I wanted and neatly parses the emails into fromAddress, subject, body and attachments. It even saves the attachments to specified location on your server.

https://github.com/barbushin/php-imap

While it is not a Symfony2 Bundle, it is very easy to integrate into Symfony by supplying the class with a namespace and then using it in your desired controller.

like image 105
Magnanimity Avatar answered Sep 30 '22 01:09

Magnanimity