Receiving / retrieving email in CakePHP
Asked Answered
G

3

6

I am developing a basic yet highly customized CRM for a small training centre which has the ability to store student records and also send emails to them. I'm using SwiftMailer following this excellent tutorial in CakePHP to accomplish the sending part.

Of course, students are sometimes going to reply to emails and I'd like to retrieve them within my CRM and store them along with the student record.

However, I cannot find a single reference to doing this. I've tried the following Google searches: "receiving email cakephp" , "retrieving email cakephp" and even "email client cakephp" but all of these queries give results relating to sending mail rather than receiving it -- very frustrating!

Finally, I broadened my search to non-cake solutions and found someone recommending a library called ezComponents. It doesn't seem to have had any active development for about a year, but it includes an email receiving class which is exactly what I want. Unfortunately, I have no idea how to add this to CakePHP and the only post I've been able to find on the entire web on the matter doesn't exactly go into much detail. It's certainly not a step-by-step tutorial on using ezComponents on CakePHP like the SwiftMailer tutorial I mentioned above.

I also found a class on Google Code called php-imap which looks like it would do the job but, again, I haven't the slightest clue how to get it working happily in Cake like SwiftMailer is.

I realize that I may have to learn how to package classes for use in Cake by myself but I'm asking this question first on the off-chance that there is already a Cake-friendly solution to this problem that I just haven't realized :-)

Joseph

Grosgrain answered 12/6, 2011 at 3:34 Comment(1)
I don't have an answer for you, but I imagine you need a mailbox and to monitor it using either IMAP or POP3 (and find PHP classes to do that, eg pear.php.net/packages.php?catpid=14&catname=Mail). Not sure about William Golden's answer below, but I presume to do otherwise you would be effectively be building your own email server.Artificiality
G
7

Thanks to everyone for your answers, but I've been doing some more searching and it looks like the solution is actually incredibly simple.

Basically, with the help of a plugin, I can set up the mail server in databases.php as a datasource and then write a Model and Controller to interact with it.

Here's the example I found: https://github.com/kvz/cakephp-emails-plugin

Edit: the repo has been deprecated and is now available at https://github.com/kvz/deprecated/tree/cakephp-emails-plugin

Grosgrain answered 15/6, 2011 at 1:47 Comment(4)
Quick followup: I implemented this last night and it works a charm. Checking emails via a model makes so much sense and makes it possible to fully enjoy all of the other benefits of Cake when interacting with the email data.Grosgrain
Hello Joseph.. I have not found plugin on Git.. Can you send it to me.. ?Dunk
Ok, I'll have a look for it in the morning (it's 10pm + 5 beers here now) and if I can't find it online I'll upload the copy I have somewhere and send you the link.Grosgrain
Ok, it looks like he's moved it to github.com/kvz/deprecated/tree/cakephp-emails-pluginGrosgrain
S
2

You will want to pipe your email to PHP and use stdin:// to read the contents of the email and add the e-mail to your database.

I've done this with cake and the simplest way is to make a Cake console application to handle the parsing. Also using cpanel's account level filtering to generate the pipe is really simple.

http://forums.cpanel.net/f5/piping-mail-php-scripts-howto-checklist-50985.html

http://www.evolt.org/incoming_mail_and_php

Sphagnum answered 13/6, 2011 at 20:52 Comment(1)
@william : thankx to you.. will it definitely work with CakePHP ? It will really help full to me if you can write a help steps summery for me ? Means how could i do this with your experience. Actually i am not getting any help.. and not have experienced with Cake Shell. :(Dunk
T
0

Sounds like you want to include SwiftMailer as a Cake plugin, amirite?

http://book.cakephp.org/view/1111/Plugins

-- if you want to package it yourself. Otherwise, a cursory search of the Bakery yielded this result:

http://bakery.cakephp.org/articles/sky_l3ppard/2009/11/07/updated-swiftmailer-4-xx-component-with-attachments-and-plugins

Hopefully it will at least get you pointed in the right direction. HTH. :)

Tokharian answered 13/6, 2011 at 3:54 Comment(3)
Thanks for your reply and sorry if I wasn't clear. I've already included SwiftMailer using the instructions at that exact URL. Now I'm looking for another plugin to receive email instead of send it. ezComponents seems to offer what I need, but based on what I have read it has to be packaged as a Vendor library and not a Plugin, just like SwiftMailer. The only info in the CakePHP Book says that Vendors are no longer supported in CakePHP 1.3 which doesn't make much sense as SwiftMailer is working as a Vendor, but, anyway, they don't give info on how to package a library as a vendor.Grosgrain
The status on Vendor support and phase out from vendors to plugins is an area of the Cookbook / Cake roadmap I don't really understand, honestly - but I do know that even if it's deprecated, Cake 1.3 still supports Vendors (cos I use vendored stuff! PHPExcel, firephp integration with Cake, etc.) So if that solves your problem, I'd say check the changelogs and roadmaps but a solution that works > a solution that's planned, amirite? ;) Here's a link to the basic changelog in the cookbook - book.cakephp.org/view/1571/Vendors-Test-Suite-schemaTokharian
Just to clarify: vendors are still supported, only support for vendor asset serving (ie. serving files from js/css/img directories) has been moved to plugins/themes only. If you wanted to use CKeditor as a vendor for example, which comes with it's own js/css/img files, it would be better packaged as a plugin. PHP only vendors, such as SwiftMailer classes, still work as vendors.Guillen

© 2022 - 2024 — McMap. All rights reserved.