Search code examples
objective-ccocoaemailscripting-bridge

Can't send attachments from draft (Mail.app)


I am trying to send a draft created with Mail.app.

As drafts have no send method, I'm having to get all the content from the draft, and create a new e-mail with it. That should be ok, but... Attachments aren't getting through.

I am using this:

outgoing.content = message.content;

Where outgoing is the message I am creating and message is the draft I am reading from.

I tried looping through the attachments of the message and adding them manually but I always get this:

*** -[SBElementArray addObject:]: can't add an object that already exists.

This is how I am looping through them:

for (int i=0; i<[message.content.attachments count]; i++) {
            MailAttachment *anAttachment = [message.content.attachments objectAtIndex:i];
            if (![outgoing.content.attachments containsObject:anAttachment]) {
                NSLog(@"File Path: %@", anAttachment.fileName);
                MailAttachment *newAttachment = anAttachment;
                [outgoing.content.attachments addObject:newAttachment];
            }
}

It should be worth noting that the File Path NSLog always comes out as (null), no matter what.

Would appreciate any help here.


Solution

  • From my research, Mail.app's AppleScript/ScriptingBridge API is pretty much broken when it comes to reading messages and getting its contents.