Data Rich email like iPhoto/Aperture?

  • I'd like to push some attributed strings into an email for my users
    to address and send out... something like what iPhoto or Aperture
    do.  I have an applescript that will attach a file, but it won't
    inline it.  NSMailDelivery has been deprecated on leopard so thats
    not really an option (not that it was really any good before), and
    I'd rather not talk directly to an SMTP server.  Any ideas?

    Thanks
    ->Ben
    --
    "Pinky, you've left the lens cap of your mind on again." - The Brain
  • On Oct 31, 2007, at 10:19 PM, Ben Lachman wrote:

    > I'd like to push some attributed strings into an email for my users
    > to address and send out... something like what iPhoto or Aperture
    > do.  I have an applescript that will attach a file, but it won't
    > inline it.  NSMailDelivery has been deprecated on leopard so thats
    > [sic] not really an option (not that it was really any good before),
    > and I'd rather not talk directly to an SMTP server.  Any ideas?

    This really isn't a Cocoa question, so you should probably take it to
    applescript-users, but I'm not sure what you mean by "will attach a
    file, but it won't inline it." The following AppleScript works pretty
    well on my machine:

    tell application "Mail"
    set theLocation to "/tmp/file.txt"
    set theBody to "Lorem ipsum dolor sit amet, consectetur adipisicing
    elit, sed do eiusmod tempor incididunt ut labore et dolore magna
    aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
    laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
    in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
    pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
    culpa qui officia deserunt mollit anim id est laborum." & return &
    return & return & "Lorem ipsum dolor sit amet, consectetur adipisicing
    elit, sed do eiusmod tempor incididunt ut labore et dolore magna
    aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
    laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
    in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
    pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
    culpa qui officia deserunt mollit anim id est laborum."
    set theSubject to "Lorem ipsum"
    set newMessage to (make new outgoing message with properties
    {subject:theSubject, content:theBody})
    tell newMessage to make new cc recipient with properties {address:"CC
    people <people...>"}
    tell newMessage to make new attachment with properties {file
    name:theLocation} at after second paragraph
    activate
    end tell

    NSMailDelivery is designed for directly sending messages, and it
    sounds like you want to bring up a compose window in Mail, not
    directly send a message. If this app is Leopard-only, you might look
    in to using the Scripting Bridge to make this in to native Objective-C
    code, which will give you a big speed and sanity boost.

    -> jp
  • My point, which perhaps wasn't clear enough, was that I don't think
    Applescript is going to work.  It doesn't seem to be able to handle
    rich text data very well (at all?) and particularly not from within
    cocoa.  This being the case, I am wondering if their are any
    alternate solutions out there to get rich text data into an email.

    ->Ben

    On Nov 1, 2007, at 10:10 AM, Jim Puls wrote:

    > On Oct 31, 2007, at 10:19 PM, Ben Lachman wrote:
    >
    >> I'd like to push some attributed strings into an email for my
    >> users to address and send out... something like what iPhoto or
    >> Aperture do.  I have an applescript that will attach a file, but
    >> it won't inline it.  NSMailDelivery has been deprecated on leopard
    >> so thats [sic] not really an option (not that it was really any
    >> good before), and I'd rather not talk directly to an SMTP server.
    >> Any ideas?
    >
    > This really isn't a Cocoa question, so you should probably take it
    > to applescript-users, but I'm not sure what you mean by "will
    > attach a file, but it won't inline it." The following AppleScript
    > works pretty well on my machine:
  • On 01.11.2007, at 06:19, Ben Lachman wrote:

    > I'd like to push some attributed strings into an email for my users
    > to address and send out... something like what iPhoto or Aperture
    > do.  I have an applescript that will attach a file, but it won't
    > inline it.

    - I'd guess Aperture and iPhoto use helper AppleScripts to talk to the
    Mail clients. Find those and analyze those.
    - if you cannot open them, set AEDebug and friends in the environment
    and see the events that are sent in order to compose a Mail you want
    to mimick.

    Regards,
    Tom_E
  • On 11/1/07, Ben Lachman <blachman...> wrote:
    > My point, which perhaps wasn't clear enough, was that I don't think
    > Applescript is going to work.  It doesn't seem to be able to handle
    > rich text data very well (at all?) and particularly not from within
    > cocoa.  This being the case, I am wondering if their are any
    > alternate solutions out there to get rich text data into an email.

    Just thinking out loud here... but what about Automator? You could
    create a workflow involving Mail and then run it with
    <http://developer.apple.com/documentation/AppleApplications/Reference/AMWork
    flow_class/Reference/Reference.html#//apple_ref/occ/clm/AMWorkflow/runWorkf
    lowAtURL:withInput:error:
    >.

    Note: AMWorkflow appears to be a 10.5 thing only.
  • On 2 Nov 2007, at 07:58, Thomas Engelmeier wrote:

    >
    > On 01.11.2007, at 06:19, Ben Lachman wrote:
    >
    >> I'd like to push some attributed strings into an email for my
    >> users to address and send out... something like what iPhoto or
    >> Aperture do.  I have an applescript that will attach a file, but
    >> it won't inline it.
    >
    > - I'd guess Aperture and iPhoto use helper AppleScripts to talk to
    > the Mail clients. Find those and analyze those.
    > - if you cannot open them, set AEDebug and friends in the
    > environment and see the events that are sent in order to compose a
    > Mail you want to mimick.
    >
    > Regards,
    > Tom_E

    Something like this should work (you'll have to fiddle with the
    constants and macros - I just cut and pasted from my code).

    I'm pretty sure that the AppleScript was adapted from a sample
    online, but I don't have the original reference.

    - (BOOL) sendMailUsingAppleMailTo:(NSString *)toAddress from:
    (NSString *)fromAddress path:(NSString *)path subject:(NSString *)
    theSubject message:(NSString *)theMessage
    {
        NSString *scriptPath = [[NSBundle mainBundle]
    pathForResource:kIrisSendAppleMailScript
    ofType:kIrisSendAppleMailScriptSuffix];
        NSAssert2(scriptPath != nil, @"Could not find %@.%@ in
    Resources", kIrisSendAppleMailScript, kIrisSendAppleMailScriptSuffix);

        NSURL* url = [NSURL fileURLWithPath:scriptPath];
        NSAssert1(url != nil, @"Could not transform %@ into a URL",
    scriptPath);

        NSDictionary* errors = [NSDictionary dictionary];
        NSAppleScript* appleScript =
            [[NSAppleScript alloc] initWithContentsOfURL:url
    error:&errors];

        NSAssert1(appleScript != nil, @"Applescript would not compile: %
    @", errors);

        // create the first parameter
        NSAppleEventDescriptor* theSenderAddressDescriptor =
    [NSAppleEventDescriptor descriptorWithString:fromAddress];
        NSAppleEventDescriptor* theAddressDescriptor =
    [NSAppleEventDescriptor descriptorWithString:toAddress];

        NSAppleEventDescriptor* theMessageDescriptor =
    [NSAppleEventDescriptor descriptorWithString:theMessage];

        NSAppleEventDescriptor* theSubjectDescriptor =
    [NSAppleEventDescriptor descriptorWithString:theSubject];

        NSAppleEventDescriptor* theAttachment = [NSAppleEventDescriptor
    descriptorWithString:path];

        // create and populate the list of parameters (in our case just
    one)
        NSAppleEventDescriptor* parameters = [NSAppleEventDescriptor
    listDescriptor];
        int index = 1;
        [parameters insertDescriptor:theSenderAddressDescriptor
    atIndex:index++];
        [parameters insertDescriptor:theAddressDescriptor atIndex:index++];
        [parameters insertDescriptor:theSubjectDescriptor atIndex:index++];
        [parameters insertDescriptor:theMessageDescriptor atIndex:index++];
        [parameters insertDescriptor:theAttachment atIndex:index++];

        // create the AppleEvent target
        ProcessSerialNumber psn = {0, kCurrentProcess};
        NSAppleEventDescriptor* target =
            [NSAppleEventDescriptor
    descriptorWithDescriptorType:typeProcessSerialNumber
                                                            bytes:&psn
                                                          length:sizeof
    (ProcessSerialNumber)];

        // create an NSAppleEventDescriptor with the script's method
    name to call,
        // this is used for the script statement: "on show_message
    (user_message)"
        // Note that the routine name must be in lower case.

        NSAppleEventDescriptor* handler =
            [NSAppleEventDescriptor descriptorWithString:
    [kIrisSendAppleMailRoutineName lowercaseString]];

        // create the event for an AppleScript subroutine,
        // set the method name and the list of parameters
        NSAppleEventDescriptor* event =
            [NSAppleEventDescriptor
    appleEventWithEventClass:kASAppleScriptSuite

    eventID:kASSubroutineEvent
                                            targetDescriptor:target

    returnID:kAutoGenerateReturnID

    transactionID:kAnyTransactionID];
        [event setParamDescriptor:handler forKeyword:keyASSubroutineName];
        [event setParamDescriptor:parameters forKeyword:keyDirectObject];

        // call the event in AppleScript
        if (![appleScript executeAppleEvent:event error:&errors]);
        {
            // report any errors from 'errors'
            GALLERYWINDOWCONTROLLERLOG(@"Applescript execution failed: %
    @", errors);
        }

        [appleScript release];

        return YES;
    }

    ====

    on newMessage(theSenderAddress, theAddress, theSubject, theBody,
    theAttachment)
    tell application "Mail"

      set theSender to (theSenderAddress & " <" & theSenderAddress & ">")
    as string

      -- Find the Sending address
      set everyAccount to every account
      repeat with eachAccount in everyAccount
      set everyEmailAddress to email addresses of eachAccount
      if (everyEmailAddress is not equal to missing value) then
        repeat with eachEmailAddress in everyEmailAddress
        if eachEmailAddress is equal to theSenderAddress then
          set theSender to (full name of eachAccount & " <" &
    eachEmailAddress & ">") as string
        end if
        end repeat
      end if
      end repeat

      -- We should check the sender here. TODO!!!

      -- Properties can be specified in a record when creating the
    message or
      -- afterwards by setting individual property values.
      set newMessage to make new outgoing message with properties
    {subject:theSubject, content:theBody & return & return}
      tell newMessage
      -- Default is false. Determines whether the compose window will
      -- show on the screen or whether it will happen in the background.
      set visible to true
      set sender to theSender
      make new to recipient at end of to recipients with properties
    {address:theAddress}
      tell content
        if (theAttachment is not equal to "") then
        -- Position must be specified for attachments
        make new attachment with properties {file name:theAttachment} at
    after the last paragraph
        end if
      end tell

      end tell

      -- Bring the new compose window to the foreground, in all its glory
      activate
    end tell
    end newMessage
previous month november 2007 next month
MTWTFSS
      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    
Go to today