Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract String from Email

Status
Not open for further replies.

metaphiz

Programmer
Jun 30, 2004
91
US
We need to connect to a database feed. The feed URL changes daily and is included in an email. We need to take the email text and send it to a CF script as a string which identifies the current location of the database file. How can we do this with ColdFusion and/or Windows server programs? We are a bit more used to programing in a UNIX/PHP environment. In that situation we would use procmail for the key piece which is taking the email contents and sending it as a variable/string to our DB processing script.
 
metaphiz,

1) use cfpop to retrieve the email from your mail server
2)then use a regex on the email content to find the url within it. something like RefindNoCase("https?://([-\w\.]+)+:)\d+)?(/([\w/_\.]*(\?\S+)?)?)?", emailcontent, "true") should work
3) the above will return a structure with two arrays in it, detailing the start position and the length of the match, using the Mid() function you'll be able to get the url of the feed

I'll try and post some code later on

Hope this helps!

Tony
 
This is untested, but looks like it should work:

Code:
<cfpop action="GETALL" name="qryMessages" server="your_server" username="your_username" password="your_password">

<cfset found = 0>
<cfloop query="qryMessages">
	<cfif NOT CompareBoCase(qryMessages.Subject, "Your_subject")>
		<cfset MessageURLLink = ReFindNoCase("https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?", qryMessages.Body, 0, 'True')>
		<cfif isStruct(variables.qryMessages)>
			<cfset MessageURL = Mid(qryMessages.Body, variables.MessageURLLink.pos,variables.MessageURLLink.len)>
			<cfset found = 1>
			<cfbreak>
		</cfif>
	</cfif>
</cfloop>

<cfif NOT Found>
	No found
<cfelse>
	<cfoutput>#MessageURL#</cfoutput>
</cfif>

Hope this helps!

Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top