ColdFusion Muse

Creating an "On Behalf Of" From Address Using Cfmail

Mark Kruger October 25, 2005 6:21 PM Coldfusion Tips and Techniques Comments (4)

If you use MS Outlook and you subscribe to any of the email lists from figleaf.com, you may have noticed the informative way that messages are displayed. The "sender" is identified as the list server but the address of the actual sender is also included with the tag line of "on behalf of". So, if boy@george.com sends a message to list-serve@rollingstone.com, the from would be displayed as list-serv@rollingstone.com on behalf of boy@george.com. It took a while for me and my good friend Tracy Rice figure out how to do this in Coldfusion.

Here's a screen shot of the effect we wanted to create:


First we grabbed a raw message file from the mail server that had been sent to our favorite figleaf list the flashcoders list. What we saw was more than the usual gobbly gook of mail headers (actual email addresses removed).
Message-ID: <003e01c5d8ea$1e17cbb0$1400a8c0@blahblah>
From: "mrRogers" <mr.rogers@myNeighbor.net>
To: "Flashcoders mailing list" <*flashcoders list serve email address*>
References: <*message id reference*>
   <*messageid reference*>
Subject: Re: [Flashcoders] FileReference class [Get path of a selected file]
Date: Tue, 25 Oct 2005 00:27:28 +0200
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Original
X-BeenThere: *flashcoders email address again*
X-Mailman-Version: 2.1.5
Precedence: list
Reply-To: Flashcoders mailing list <*flashcoders list serve email address*>
List-Id: Flashcoders mailing list <flashcoders.chattyfig.figleaf.com>
List-Unsubscribe: <http://chattyfig.figleaf.com/mailman/listinfo/flashcoders>;,
   <mailto:*flashcoders list serve email address*>
List-Archive: <http://chattyfig.figleaf.com/pipermail/flashcoders>;
List-Post: <mailto:*flashcoders list serve email address*>
List-Help: <mailto:*flashcoders list serve email address*>
List-Subscribe: <http://chattyfig.figleaf.com/mailman/listinfo/flashcoders>;,
   <mailto:*flashcoders list serve email address*>
Sender: *flashcoders list serve email address*
Errors-To: *flashcoders list serve email address*
Return-Path: <*flashcoders list serve email address*>
X-Envelope-From: *flashcoders list serve email address*
X-Envelope-To: *coldfusion muse's email address*

Let's just stand back a moment in awe of all the really neat stuff that goes on behind the scenes when you send an email. So many things have to go right for it to actually get into my mailbox - yet even folks who don't know me can express concern over the size of my penis and worry about my interest rate. Isn't life in the Internet age grand.

Anyway, Tracy took this list of headers and started inserting them into test mail messages until he got the effect he was looking for. It turns out that the "sender" header is all you need to cause the neat little message. This Coldfusion code creates the "on behalf of" tag line in the from address.

<Cfmail
   from="mr.rogers@theneighborhood.com"
   to="mr.greenjeans@neighborhood.ocm"
   subject="Corn as High as an Elephants Ear">

   
   <cfmailparam name="sender" value="milkman@Farm.com">
Greeny,

How's it hanging?

</CFMAIL>

At this point I only know that it works in Outlook. If you know of other email clients that work with this approach - do tell.

  • Share:

4 Comments


Leave this field empty

Write a comment

If you subscribe, any new posts to this thread will be sent to your email address.

  • James Moberg's Gravatar
    Posted By
    James Moberg | 10/25/05 6:07 PM
    When using Eudora's "Redirect" button, it changes the FROM address to:
    From: <milkman@Farm.com> (by way of Mr Rogers <mr.rogers@theneighborhood.com>)

    I tried this and it does work using CFMail (CFMX6.1):
    from="<milkman@Farm.com> (by way of Mr Rogers <mr.rogers@theneighborhood.com>)"
    (I sent the message to a gmail account and it only states from milkman@farm.com... You have to view source to even view the "by way of" info.)

    The problem is that SPF Filters will identify that the outbound mailserver used by "theneighborhood.com" is not authorized to send mail on behalf of "Farm.com". If SPF is properly configured for "Farm.com", the message will be immediately deleted or bounced (not good).

    I'll test the latest 7.0 beta version of Eudora to see if it performs redirects like this too as it will present a big problem with SPF filters.
  • James Moberg's Gravatar
    Posted By
    James Moberg | 10/25/05 6:24 PM
    I got it to bypass SPF while showing someone else's email address and doing the on-behalf-of function. You have to properly define the Return-Path (er, cftalk for "failto") parameter. Properly setting the failto will allow you to send the message using this technique. (Please note that you'll also get any bounced messages as a result, so use a garbage collector address or set up filters on your mail server.)

    Here's the code:
    <cfmail from="'Website Visitor Name' <user@domain.com> (by way of MyWebsiteCompany <myusername@mydomain.com>)"
    to="anotheruser@anotherdomain.com"
    subject="Any ol' subject will work, of course"
    failto="myusername@mydomain.com">
    This is a test message.
    </cfmail>
  • Mark's Gravatar
    Posted By
    Mark | 10/25/05 7:08 PM
    James - awesome information. Thanks! I'll work to create a supplimental post.
  • James Moberg's Gravatar
    Posted By
    James Moberg | 10/25/05 7:16 PM
    Sorry about that... I was using CF5 for the FROM address trick (and it worked) and the "failto" is only available when using CFMX6+. When using the CF5 FROM Address trick on CFMX, CFMail reformats the address to:
    "by way of Mr Rogers <mr.rogers@theneighborhood.com>" <milkman@Farm.com>

    ... and the above address looks really strange in the FROM field when you receive your email.

    Is there any way to prevent CFMX from reformatting the address? I'm not sure what the RFC states (I'll look into it), but Eudora adds the information as I've stated before and it is displayed in the FROM address (And looks nice and is SPF compliant). I've tested the Eudora-type message with my mail servers and gmail and they both accept the From on-behalf-of address.