August 14, 2015
getHeaders – a new attribute in the cfexchangemail tag
Comments
(0)
August 14, 2015
getHeaders – a new attribute in the cfexchangemail tag
Newbie 25 posts
Followers: 1 people
(0)

With ColdFusion 11 Update 3, we have introduced a new parameter called “getHeaders”, in the “cfExchangeMail” tag. It accepts a boolean value. When set to true, cfExchangeMail returns a query with an additional “InternetHeader” column. This column contains a struct containing key-value pairs of the email-headers associated with each message.

Email message headers provide technical details about the message, such as who sent it, the software used to compose it, the version of the MIME protocol used by the sender etc. 

On Exchange 2010, the fields that are returned are: CC, Content-Transfer-Encoding, Content-Type, Date, From, MIME-Version, Message-ID, Received, Return-Path, Subject, To, X-MS-Exchange-Organization-AuthAs, X-MS-Exchange-Organization-AuthSource, X-Mailer.

You may reference this weblink for the detailed list of the fields and their description.

You can put this new feature to any good use that suites your purpose. I will dwell on one such use case below.

In MS Exchange 2010 and later, the “ToId” column in the retrieved messages query contains the primary email address of the sender. A primary email address can have multiple aliases. If you need to retrieve the email-alias the message was sent to, you can make use of this new attribute.

Here’s an example that demonstrates the usage the tag in the context of the use case discussed above:

<cfmail from=”#frm_usr_email#” to=”#to_usr_alias#” cc=”#cc_usr_alias#” subject=”#msg_sub#”  server= “#exchangeServerIP#” port = “25”>

———– testing mail to an alias address ————

</cfmail>

<cfset sleep(5000)>

<cfexchangeConnection action=”open” username =”#to_usr#” password=”#password#” server=”#exchangeServerIP#” serverversion=”#version#” protocol=”#protocol#” connection=”excon”>

<cfexchangemail action=”get” name=”usr_msgs” connection=”excon” getheaders=true folder=”Inbox”>

<cfexchangefilter name=”fromID” value=’#frm_usr#’>

<cfexchangefilter name=”subject” value=”#msg_sub#”>

</cfexchangemail>

<cfif usr_msgs.recordcount GTE 1>

info from cfexchangemail fields:<br>

<cfloop query=”usr_msgs”>

<cfoutput>

#usr_msgs.subject#<br> 

#usr_msgs.CC#<br> 

#usr_msgs.fromId#<br>

</cfoutput>

</cfloop>

info from cfexchangemail.internetHeaders fields:<br>

<cfloop query=”usr_msgs”>

<cfoutput>

#ReplaceList(usr_msgs.internetHeaders[“from”][1], “>,<“, “,”, “,”, “,”)#<br>

#ReplaceList(usr_msgs.internetHeaders[“to”][1], “>,<“, “,”, “,”, “,”)#<br>

#ReplaceList(usr_msgs.internetHeaders[“cc”][1], “>,<“, “,”, “,”, “,”)#<br>

</cfoutput>

</cfloop>

</cfif>

 

You can reference the bugbase, for the enhancement request originally logged for this feature.

0 Comments
Add Comment