Scripting Bridge & Mail

  • Hello List,

    I'm trying to generate an Email via Apple Scripting Bridge. Everything works fine, but can't add an attachment to it. I had tryed several ways, but it doesn't work. Can anybody help me to get it work?

    Here ist a code snippet:

        AppleMailApplication *mail = [SBApplication applicationWithBundleIdentifier: @"com.apple.mail"];
        AppleMailOutgoingMessage *message = [[[mail classForScriptingClass: @"outgoing message"] alloc] init];

        NSDictionary *path = [NSDictionary dictionaryWithObject: @"Merkur:Users:schmidt:Desktop:image.tiff" forKey: @"file name"];
        [[mail outgoingMessages] addObject: message];

        [message setSubject: @"This is my subject";
        [message setContent: @"This ist my content";
        [message setVisible: YES];

      // This doesn't work, but I don't not why.
        AppleMailAttachment *attachment = [[[mail classForScriptingClass: @"attachment"] alloc] initWithProperties: path];
        [[[message content] attachments] addObject: attachment];
        // [attachment setFileName: @"Merkur:Users:schmidt:Desktop:DiscItemDisc.tiff"];

        [mail activate];

    Thanks so far,
    Peter
  • > NSDictionary *path = [NSDictionary dictionaryWithObject:
    > @"Merkur:Users:schmidt:Desktop:image.tiff" forKey: @"file name"];

    The string used in this dictionary is not a valid file path. In this
    case it should be e.g.:

    @"/Users/schmidt/Desktop/image.tiff"

    or even better:

    [NSHomeDirectory() stringByAppendingPathComponent:@"Desktop/
    image.tiff"];

    Regards,
    Mani
    --
    http://www.mani.de
    iVolume - Loudness adjustment for iTunes.
    LittleSecrets - The encrypted notepad.
  • Am 29.02.2008 um 14:55 schrieb Manfred Schwind:

    > @"/Users/schmidt/Desktop/image.tiff"
    >
    > or even better:
    > [NSHomeDirectory() stringByAppendingPathComponent:@"Desktop/
    > image.tiff"];

    The Path is not the problem (the hardcoding is only for testing). If
    I'm trying to set it path after addig the attachment, the error log
    says that the object isn't assigned to a container.
  • Peter Schmidt wrote:

    > I'm trying to generate an Email via Apple Scripting Bridge.
    > Everything works fine, but can't add an attachment to it.

    The AttachToMail sample project in appscript's svn repository shows
    how to do this using objc-appscript.

    http://appscript.sourceforge.net/objc-appscript.html

    HTH

    has
    --
    http://appscript.sourceforge.net
    http://rb-appscript.rubyforge.org
  • Peter, 

    Apple has just posted an example project of using SB with Mail

    http://developer.apple.com/samplecode/SBSendEmail/index.html

    It deals with attachments too.

    Pavel.
  • Am 29.02.2008 um 20:56 schrieb Pavel Kapinos:

    > Apple has just posted an example project of using SB with Mail
    >
    > http://developer.apple.com/samplecode/SBSendEmail/index.html
    >
    > It deals with attachments too.

    Thank you very much! This es _exactly_ what I'm looking for. And I've
    found my Error:

    Wrong:
    NSDictionary *path = [NSDictionary dictionaryWithObject: @"/Users/
    schmidt/Desktop/Bild1.png" forKey: @"file name"];

    Right:
    NSDictionary *path = [NSDictionary dictionaryWithObject: @"/Users/
    schmidt/Desktop/Bild1.png" forKey: @"fileName"];

    Greetings,
    Peter