I'm working on some code to generate EML files dynamically. My goal is to use cfpop to read messages and provide a quick 'Download' link that will generate an EML file. These files can then be opened in a native desktop client like any other mail. I've got that part working (and will be blogging it soon), but when I went to test against real email, I ran into an interesting issue.
For my testing I hit a gmail account. Now - that by itself provides a bit of a problem because cfpop doesn't support SSL. You can get around it with a bit of Java (and forgive me for not citing the person who did this code - when I googled it I found 2-3 solutions from our community).
<cfset javaSystem = createObject("java", "java.lang.System") />
<cfset jProps = javaSystem.getProperties() />
<cfset jProps.setProperty("mail.pop3.socketFactory.class", "javax.net.ssl.SSLSocketFactory") />
<cfset jProps.setproperty("mail.pop3.port",995) />
<cfset jProps.setProperty("mail.pop3.socketFactory.port", 995) />
<cfpop action="getAll" name="messages"
server="pop.gmail.com" username="bob@camdenfamily.com"
password="moo" port="995">
I ran the code and it worked perfectly. Once. I looked in my browser that had the gmail account open and I could still see the emails there, so I know CF didn't delete anything. I sent the account another email. Ran my CFM - saw it return just the new email - and on a reload the result was blank again. In GMail you have settings for what to do when mail is accessed via POP, but I had configured this to simply leave it as is.

On a whim, I double checked the docs for cfpop and noticed that it includes a debug attribute. I had a vague recollection of this attribute but never actually used it. I turned it on and noticed something pretty interesting.
First off - debug will log all of the POP commands and results. Here is a snippet.
DEBUG: setDebug: JavaMail version 1.4.2
DEBUG: getProvider() returning javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]
DEBUG POP3: connecting to host "pop.gmail.com", port 995, isSSL false
S: +OK Gpop ready for requests from 76.72.15.75 i1pf10228089yhm.15
C: USER bob@camdenfamily.com
S: +OK send PASS
C: PASS foo
S: +OK Welcome.
C: STAT
S: +OK 1 2108
C: UIDL
The STAT command returns the number of messages and the size. I noticed that after I ran cfpop and it read the email, and then I ran it again, I would get:
C: STAT
S: +OK 0 0
C: QUIT
S: +OK Farewell.
This seems to imply that GMail did something to my messages after CFPOP read them. Oddly - in my browser - where I was just looking at the list of messages and not reading anything - still showed all the email as new and unread. When I looked at the commands CFPOP sent in for when it did find a message, all it did was a TOP and a RETR. From my reading of the docs, RETR gets a message, but doesn't do anything else to it. In other words, it's not deleting it for sure.
Unfortunately at this point I didn't know what else to do. It was certainly interesting to see all the behind the scenes POP calls with the debug attribute though. I ended up simply signing up for an AOL account. When I tested there (it also needs the SSL hack) it worked perfectly.
Archived Comments
CFPOP has always had issues. We tried to use it to handle bounce processing and certain e-mails would simply crash the system. Attachments were always problematic too.
Did you check the first radio button in your screenshot? Try that if you haven't.
Ray,
When you are retrieving e-mail via POP3 from Gmail the two settings you were looking at do the following things:
1. Determine what e-mail will be presented via POP from that point forward. The options are either any new messages from the time you set the option or all messages ever received or to turn off POP3 access.
2. The second option determines what is done in the WEB interface after a message is retrieved via POP3. It does not change the behavior of the POP3 server.
I have noticed that no matter what settings you apply, once you retrieve your e-mail via POP3 from your Gmail account it is removed from the POP3 list regardless of what you've configured for the second option. The second option just determines if the copy in the web interface is archived, marked read, left alone, etc.
It also seems that you don't need to send a delete command via POP3 to have the POP3 system clear a message from the list, simply retrieving the message removes it from the list of available messages.
If you change the first option to "all mail" and apply the setting it will make every single e-mail in your mailbox available for retrieval via POP3, however, once you have retrieved them via POP3 once they are removed from the list of messages available for retrieval via POP3 for future connections.
I'm not sure why Google chose to have it clear the message after retrieval instead of waiting for a command to remove it from the server, but that's the behavior I've seen when using POP3 to access my Gmail account in the past.
-Az
@Dave: Yep, it was selected. It just doesn't stay checked when you come back to the form.
@Az: That sees to mesh with everything I've seen. I wonder why.
@Ray:
Just keep in mind that GMail was never really designed for POP retrieval of mail--it was designed to be a web-based solution. It's not a traditional mail server--it's custom software that doesn't necessarily conform with the spec.
My suspicion is because Google really doesn't want you deleting mail from Gmail, they implemented their POP protocol to just flag the mail as being downloaded w/no way to reset that flag.
I doubt there's anything you can do to work around this, as I suspect it's completely at the server-side of things. That said, one thing you might be able to do is switch over to IMAP for Gmail. Using IMAP should allow you to keep reading in the same message over and over.
Thanks Ray and everyone else that has commented in this thread. I recently switched from running my own Exchange Server to using Google Apps and have a bounced mail routine that connected to a mailbox using cfpop and this info greatly reduced the time it took to get it functional again!
The following suggestion works GREAT:
"To enable Recent mode, replace 'username@...' in the Username field of your POP client settings with 'recent:username@...' and ensure that the Leave messages on server option in your POP client is enabled."
It worked for me!
It comes from another site (not my own idea), and I would put the URL here if this site allowed URLs (says my comment is flagged as spam).
I do allow URLs, but, the spam blocker sometimes gets a bit over aggressive. ;) Thanks for sharing the tip.
Hey Ray, this code worked great for me until my IT guy told me that it was it opened up SSL on all the other poppers running on that server. I don't understand the full nature of what happened but he said something of the effect of once you "turn it on", you gotta turn it off. Thankfully that particular server was running CF10 and I didn't have to use this code anyways and was easily corrected. Unfortunately not all of our servers is CF10.
I wasn't aware that it was system wide. In theory you could reset the values after you run the cfpop.
Yea, that's what he said but excuse my ignorance, how would I do that?
Any time you set JVM properties, they affect the entire JVM. This is why you typically set them only temporarily, within a single script, then set them back to their original values. You see this when people disable the JSafe crypto provider, too.
Matt, if I had to guess, I bet getProperty(x) would work to get the original values.
Thnx guys.