Friday, February 03, 2012    
Home My Books Blog ColdFusion About Me Back    

Calendar
<< Jan 2008 >>
S M T W T F S
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    

Search

Categories
 • Acrobat (5) [RSS]
 • Adobe (110) [RSS]
 • AdobeMAX06 (45) [RSS]
 • AdobeMAX07 (59) [RSS]
 • AdobeMAX08 (66) [RSS]
 • AdobeMAX09 (39) [RSS]
 • AdobeMAX10 (34) [RSS]
 • AdobeMAX11 (27) [RSS]
 • AIR (297) [RSS]
 • Appearances (217) [RSS]
 • Books (86) [RSS]
 • CFEclipse (15) [RSS]
 • Cloud (1) [RSS]
 • ColdFusion (1477) [RSS]
 • ColdFusion Builder (22) [RSS]
 • Data Services (42) [RSS]
 • Fish Tank (5) [RSS]
 • Flash (356) [RSS]
 • Flex (561) [RSS]
 • Home Automation (5) [RSS]
 • HTML5 (21) [RSS]
 • JavaScript (2) [RSS]
 • Jobs (130) [RSS]
 • jQuery (14) [RSS]
 • JRun (14) [RSS]
 • Labs (62) [RSS]
 • LiveCycle (37) [RSS]
 • MAX (284) [RSS]
 • Mobile (238) [RSS]
 • Regular Expressions (19) [RSS]
 • RIA (21) [RSS]
 • SQL (45) [RSS]
 • Stuff (554) [RSS]
 • Tips (CF Studio) (80) [RSS]
 • Tips (CF) (795) [RSS]
 • Tips (Dreamweaver) (91) [RSS]
 • Tips (Flex Builder) (2) [RSS]
 • Using CF (167) [RSS]

Other BLOGs
 • Charlie Arehart
 • Lee Brimelow
 • Ray Camden
 • Christophe Coenraets
 • Sean Corfield
 • Mihai Corlan
 • Cornel Creanga
 • Mark Doherty
 • John Dowdell
 • Danny Dura
 • Enrique Duvos
 • Steven Erat
 • Kevin Hoyt
 • Serge Jespers
 • Adam Lehman
 • Duane Nickull
 • Miti Pricope
 • Andrew Shorten
 • Ryan Stewart
 • James Ward
 • Greg Wilson
 • Full As A Goog

RSS Feeds
 • Feed
 • Subscribe

Join my mailing list and find out about new books and other topics of interest.

Thoughts, ideas, tips, musings, and pontifications (not necessarily in that order) by Ben Forta ...
NOTE: This is my personal blog, and the opinions and statements voiced here are my own.

Viewing By Entry / Main
January 2, 2008

The Simplest BlogCFC Post Code

I wrote an app that I use to allow BlogCFC posts via e-mail. This particular blog is an internal Adobe blog, and anyone with a valid Adobe LDAP login can post to it. (I also wrote some code that updates Ray's login code so as to update tblUsers table with new users as needed).

BlogCFC has grown into quite a hefty app, but much of the code is actually used for rendering UI with locale support and more. The actual code needed to make a post (this is what gets called by the core of the BlogMail bot after it has validated the user and extracted the body and subject) is very simple. And in case anyone else wants it, this is all you need:

<!--- Post it --->
<cffunction name="blogPost" output="no">
    <cfargument name="username" type="string" required="yes">
    <cfargument name="subject" type="string" required="yes">
    <cfargument name="body" type="string" required="yes">
    <cfargument name="categories" type="array" required="yes">

    <cfset var id="">
    <cfset var alias="">

    <!--- Fake login --->
    <cfloginuser name="#username#" password="" roles="admin">

    <!--- Create alias --->
    <cfset alias=APPLICATION.blog.makeTitle(ARGUMENTS.subject)>

    <!--- Save blog entry --->
    <cfset id=APPLICATION.blog.addEntry(ARGUMENTS.subject, ARGUMENTS.body, "", alias)>
    <cfif ArrayLen(ARGUMENTS.categories)>
        <cfset APPLICATION.blog.assignCategories(id, ArrayToList(ARGUMENTS.categories))>
    </cfif>
</cffunction>

The username is needed to "login" so that the blog entry has a valid owner (BlogCFC relies on ColdFusion logins for this, and thus the <cfloginuser>). The makeTitle() call is actually optional, if you don't want an SEO type friendly URL you can skip that. addEntry() does the actual work of adding the blog entry. And assignCategories() passes the category list. (My bot code scans the subject and body for keywords and builds that category list automatically).

So, if you need to programmatically add entries to BlogCFC, instead of hacking the database tables (never a good idea), this code should be all you need.

Comments
It's funny that you just posted this as I was just mulling much the same thing around. Thanks Ben!
# Posted By Shane Zehnder | 1/2/08 5:58 PM
Ben,

so how did you send the email to the CF server? did the emails go to a mailbox and you used CFPOP on a sched task to retrieve it?
# Posted By barry.b | 1/14/08 8:55 AM
Barry, yes, exactly. I wanted team members to be able to write up entries and reports while disconnected, perhaps on flights back. They send these to an internal mailbox, and a scheduled event picks them up for processing.

--- Ben
# Posted By Ben Forta | 1/14/08 11:10 AM

  © Copyright 1997-2009 Ben Forta, All Rights Reserved