Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

IMAP with CFIMAP

DZone's Guide to

IMAP with CFIMAP

· Web Dev Zone
Free Resource

Start coding today to experience the powerful engine that drives data application’s development, brought to you in partnership with Qlik.

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:
<cfimap
 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".
<cfimap
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".
<cfimap
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":
<cfimap
action=”close”
connection = “gmailconnection” />

Create data driven applications in Qlik’s free and easy to use coding environment, brought to you in partnership with Qlik.

Topics:

Published at DZone with permission of Sagar Ganatra, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}