cfexchangemail
Description
Gets mail messages and attachments, deletes messages, and sets properties for messages on a Microsoft Exchange server.
Categories
Related
History
ColdFusion
8: Added this tag.
Syntax
delete
<cfexchangemail
required
action = "delete"
uid = "message UID,message UID,..."
optional
connection = "connection ID"
folder = "Exchange folder path">
deleteAttachments
<cfexchangemail
required
action = "deleteAttachments"
uid = "message UID"
optional
connection = "connection ID">
folder = "Exchange folder path">
get
<cfexchangemail
required
action = "get"
name = "query identifier"
optional
connection = "connection ID"
folder = "Exchange folder path">
<cfexchangefilter name = "filter type" value = "filter value">
<cfexchangefilter name = "filter type" value = "filter value">
...
</cfexchangemail>
getAttachments
<cfexchangemail
required
action = "getAttachments"
name = "query identifier"
uid = "message UID"
optional
attachmentPath = "directory path"
connection = "connection ID"
folder = "Exchange folder path"
generateUniqueFilenames = "no|yes">
getMeetingInfo
<cfexchangemail
required
action = "getMeetingInfo"
meetingUID = "meeting UID"
name = "query identifier"
optional
connection = "connection ID"
mailUID = "message UID">
move
<cfexchangemail
required
action = "move"
destinationFolder = "Exchange folder path"
optional
connection = "connection ID"
folder = "Exchange folder path">
<cfexchangefilter name = "filter type" value = "filter value">
<cfexchangefilter name = "filter type" value = "filter value">
...
</cfexchangemail>
set
<cfexchangemail
required
action = "set"
message = "#structure with values to set#">
uid = "message UID">
optional
connection = "connection ID"
folder = "Exchange folder path">
Note: If you omit the connection attribute,
create a temporary connection by specifying cfexchangeconnection tag
attributes in the cfexchangemail tag. In this case,
ColdFusion closes the connection when the tag completes. For details,
see the cfexchangeconnection tag open action.
Note: You can specify this tag’s attributes in an attributeCollection attribute
whose value is a structure. Specify the structure name in the attributeCollection attribute
and use the tag’s attribute names as structure keys.
Attributes
| Attribute | Description | Required | Default |
|---|---|---|---|
| action | all | ||
| attachmentPath | getAttachments | ||
| connection | all | ||
| destinationFolder | move | ||
| folder | all exceptgetMeetingInfo | ||
| generateUniqueFilenames | getAttachments | ||
| mailUID | getMeetingInfo | ||
| meetingUID | getMeetingInfo | ||
| message | set | ||
| name | get getAttachments getMeetingInfo | ||
| uid | delete getAttachments set |
Usage
The cfexchangemail tag performs mail actions on an Exchange server that you cannot do by using the cfmail tag. (You must use the cfmail tag to send, forward, and reply to mail messages.) Use the cfexchangemail tag to perform the following actions:
Permanently delete one or more mail messages from the server.
Get the attachments for a specific message.
Get one or more messages that conform to an optional set of filter specifications, such as the subject, sender or recipient ID, time received, and so on.
Get the attachments for a specific message.
Get detailed information about a meeting for which you have a notification, such as a meeting request or cancellation notice.
Move one or more messages from one folder to another, including to the Deleted Items folder.
Set the properties of a specific mail message.
To use this tag, you must have a connection to an Exchange server. If you are using multiple tags that interact with the exchange server, such as if you are creating several contact records, use the cfexchangeconnection tag to create a persistent connection. You then specify the connection identifier in each cfexchangemail tag, or any other ColdFusion Exchange tag, if you are also accessing tasks, contacts, or connections. Doing this saves the overhead of creating and closing the connection for each tag.
Alternatively, you can create a temporary connection that lasts only for the time that ColdFusion processes the single cfexchangemail tag. To do this, you specify the connection attributes directly in the cfexchangemail tag. For details on the connection attributes, see the cfexchangeconnection tag.
Permanently delete one or more mail messages from the server.
Get the attachments for a specific message.
Get one or more messages that conform to an optional set of filter specifications, such as the subject, sender or recipient ID, time received, and so on.
Get the attachments for a specific message.
Get detailed information about a meeting for which you have a notification, such as a meeting request or cancellation notice.
Move one or more messages from one folder to another, including to the Deleted Items folder.
Set the properties of a specific mail message.
To use this tag, you must have a connection to an Exchange server. If you are using multiple tags that interact with the exchange server, such as if you are creating several contact records, use the cfexchangeconnection tag to create a persistent connection. You then specify the connection identifier in each cfexchangemail tag, or any other ColdFusion Exchange tag, if you are also accessing tasks, contacts, or connections. Doing this saves the overhead of creating and closing the connection for each tag.
Alternatively, you can create a temporary connection that lasts only for the time that ColdFusion processes the single cfexchangemail tag. To do this, you specify the connection attributes directly in the cfexchangemail tag. For details on the connection attributes, see the cfexchangeconnection tag.
Example
The
following example gets the attachments to all mail messages in the
Inbox from docuser2 in the last week. It puts each message’s attachments
in a directory with a unique name. It cannot use the UID as a filename
because, for each message with attachments, the UID can contain
the application reports of the UID, directory path, subject, date,
and sender of the message, followed by a table that lists the message’s
attachments. The table includes the attachment name, size, and MIME
type.
<!--- Index for message attachement directory --->
<cfset i=1>
<!--- Dates for date range --->
<cfset rightNow = Now()>
<cfset lastWeek = DateAdd("d","-7", rightNow)>
<cfexchangeconnection
action="open"
username ="#user1#"
password="#password1#"
server="#exchangeServerIP#"
connection="testconn1">
<cfexchangemail action="get" folder="Inbox " name="weeksMail" connection="testconn1">
<cfexchangefilter name="FromID" value="docuser2">
<cfexchangefilter name="TimeSent" from="#lastWeek#" to="#rightNow#">
</cfexchangemail>
<cfloop query="weeksMail">
<cfif weeksmail.HasAttachment>
<cfexchangemail action="getAttachments"
connection="testconn1"
folder="Inbox/MailTest"
uid="#weeksmail.uid#"
name="attachData"
attachmentPath="C:\temp\cf_files\attachments\msg_#i#"
generateUniqueFilenames="yes">
<cfoutput>
Message ID #weeksmail.uid# attachments are in the directory
C:\temp\cf_files\attachments\Msg_#i#<br />
<br />
Message information:<br />
Subject: #weeksmail.Subject#<br />
Sent: #dateFormat(weeksmail.TimeSent)#<br />
From: #weeksmail.FromID#<br />
<br />
Attachments<br />
<cftable query="attachData" colheaders="yes">
<cfcol header="File Name" text="#attachmentFilename#">
<cfcol header="Size" text="#size#">
<cfcol header="MIME type" text="#mimeType#">
</cftable>
</cfoutput>
<cfset i++>
</cfif>
</cfloop>
<cfexchangeconnection action="close" connection="testconn1">