Skip to main content

IMAP with CFIMAP

What is IMAP?
IMAP stands for Internet Message Access Protocol. IMAP is one of the two most prevalent Internet standard protocols for e-mail retrieval, the other being the Post Office Protocol (POP). Virtually all modern e-mail clients and mail servers support both protocols as a means of transferring e-mail messages from a server.







An IMAP connection is a live connection to the server. If folders are created, they exist on your account on the server. If messages are moved or deleted, then they are moved or deleted on the server.
With POP3, your mail is saved in a mailbox on the remote server until you check your mail. When you check your mail, all of the mail is immediately downloaded to your computer and is no longer maintained on the server.
IMAP can be thought of as a remote file server, while POP3 can be thought of as a “store-and-forward” service. Ultimately they both accomplish similar tasks but often one will suit your needs better than the other.


CFIMAP:
With CFIMAP tag one can manage mails on an IMAP server.


Syntax:



 action =”DELETE | DELETEFOLDER | CREATEFOLDER | OPEN | CLOSE | RENAMEFOLDER | LISTALLFOLDERS
| MAKREAD | MOVEMAIL | GETALL | GETHEADERONLY”
attachmentpath = “string”
connection = “string”
folder = “string”
generateuniquefilenames = “yes|no”
maxrows = “integer”
messagenumber =”integer”
name = “string”
newfolder = “string”
password = “string”
port = “integer”
recurse = “true|false”
secure = “yes|no”
server = “IMAP server address”
startrow = “integer”
secure = “yes|no”
stoponerror = “true|false”
uid = “integer or comma-delimited list of integers”
username = “SMTP user ID” />

Example:

The below example demonstrates how one can retrieve mail from Gmail using CFIMAP. To do this one needs to enable IMAP in Gmail. Please follow these steps:

  • Login to Gmail with your credentials.
  • Click on the settings link.
  • Click on Select forwarding and POP/IMAP.
  • Here in the IMAP access section click on enable IMAP.

This is it and you are ready to try CFIMAP.
First open a connection with the server, this can be done by specifying server details with action="open".

server = “imap.gmail.com”
username = “yourusername”
action=”open”
secure=”yes”
password = “yourpassword”
connection = “gmailconnection” />


Please note Gmail uses SSL therefore one needs to specify secure="yes". This may vary with other email providers.
Now once the connection is available you can use the connection variable in subsequent calls. To retrieve say all the mails from the INBOX one can use CFIMAP tag with action="getAll".

action=”getAll”
connection = “gmailconnection”
name = "mails" />


Please note one can omit the step of creating an open connection and directly CFIMAP action="getAll" to retrieve mails by specifying various connection details in the same tag.
Now if one needs to close a connection and ensure that the connection is not available in the subsequent calls then use CFIMAP with action="close":

action=”close”
connection = “gmailconnection” />

Comments

Popular posts from this blog

File upload and Progress events with HTML5 XmlHttpRequest Level 2

The XmlHttpRequest Level 2 specification adds several enhancements to the XmlHttpRequest object. Last week I had blogged about cross-origin-requests and how it is different from Flash\Silverlight's approach .  With Level 2 specification one can upload the file to the server by passing the file object to the send method. In this post I'll try to explore uploading file using XmlHttpRequest 2 in conjunction with the progress events. I'll also provide a description on the new HTML5 tag -  progress which can be updated while the file is being uploaded to the server. And of course, some ColdFusion code that will show how the file is accepted and stored on the server directory.

Server sent events with HTML5 and ColdFusion

There are several ways to interact with the server apart from the traditional request\response and refresh all protocol. They are polling, long polling, Ajax and Websockets ( pusherapp ). Of all these Ajax and Websockets have been very popular. There is another way to interact with the server such that the server can send notifications to the client using Server Sent Events (SSE) . SSE is a part of HTML5 spec:  http://dev.w3.org/html5/eventsource/

De-obfuscating javascript code in Chrome Developer Tools

I had blogged about JavaScript debugging with Chrome Developer Tools  some time back, wherein I have explained how these developer tools can help in debugging javascript code. Today Google Chrome 12 was released and my Chrome browser was updated to this version. As with every release, there have been some improvements made on performance, usability etc,. One feature that stood out for me is the ability to De-obfuscate the javascript code. What is Minification? Minification is the process of removing unnecessary characters such as white spaces, comments, new lines from the source code. These otherwise would be added to make the code more readable. Minifying the source code helps in reducing the file size and thereby reducing the time taken to download the file. This is the reason why most of the popular javascript libraries such as jQuery are minified. A minified jQuery file is of 31 KB in size where as an uncompressed one is about 229 KB. Unfortunately, debugging minified javascript f...