2

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.

EduAlm
  • 813
  • 3
  • 11
  • 27
  • I'm unfamiliar with the `Mail.app` API, but it feels very strange to me that there's no mechanism to send a draft -- forcing you to rebuild a similar message just to send it feels awkward. Are you certain there's no mechanism to send a draft? – sarnold Feb 06 '12 at 23:33
  • Yes. a -(void)send method is only declared in MailOutgoingMessage*, which is what I am creating. I can't cast the draft as a MailOutgoingMessage* as it gets me a unrecognized selector when I call -(void)send;. – EduAlm Feb 06 '12 at 23:55

1 Answers1

0

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

EduAlm
  • 813
  • 3
  • 11
  • 27