views:

29

answers:

2

Hello,

When I use the Apple Scripting Bridge to send a message with an attachment the background of the message is set to black which is a problem because the text is also black. The code in question is:

MailApplication *mail = [SBApplication applicationWithBundleIdentifier:@"com.apple.Mail"];

/* create a new outgoing message object */
MailOutgoingMessage *emailMessage =
[[[mail classForScriptingClass:@"outgoing message"] alloc]
 initWithProperties:
[NSDictionary dictionaryWithObjectsAndKeys:
 emailSubject, @"subject",
 [self composeEmailBody], @"content", nil]];

/* add the object to the mail app  */
[[mail outgoingMessages] addObject: emailMessage];

/* set the sender, show the message */
emailMessage.sender = [NSString stringWithFormat:@"%@ <%@>",[[[mail accounts] objectAtIndex:playerOptions.mailAccount] fullName],[[[[mail accounts] objectAtIndex:playerOptions.mailAccount] emailAddresses] objectAtIndex:0]];
emailMessage.visible = YES;

/* create a new recipient and add it to the recipients list */
MailToRecipient *theRecipient =
[[[mail classForScriptingClass:@"to recipient"] alloc]
 initWithProperties:
 [NSDictionary dictionaryWithObjectsAndKeys:
  opponentEmail, @"address",
  nil]];
[emailMessage.toRecipients addObject: theRecipient];

/* add an attachment, if one was specified */
if ( [playerInfo.gameFile length] > 0 ) {

    /* create an attachment object */
    MailAttachment *theAttachment = [[[mail classForScriptingClass:@"attachment"] alloc] initWithProperties:
                                     [NSDictionary dictionaryWithObjectsAndKeys:
                                      playerInfo.gameFile, @"fileName", nil]];

    /* add it to the list of attachments */
    [[emailMessage.content attachments] addObject: theAttachment];
}
/* send the message */
[emailMessage send];

The actual change to the background colour occurs on the second last line, which is:

[[emailMessage.content attachments] addObject: theAttachment];

The code sections above are essentially lifted from the SBSendMail example code from Apple. At this stage I've really only made the changes necessary to integrate with the data from my application. If I build and run the SBSendMail example after freshly downloading it from Apple the message background is also changed to black with execution of the same line. It does not appear to matter which type of file is attached, where it is located, or on which computer or operating system is used.

This could be a bug in Apple's scripting bridge but has anyone come across this problem and found a solution? ALternatively does anyone know if the background colour of a MailOutgoingMessage instance can be changed with the scripting bridge?

Thanks for any assistance with this,

Naym.

A: 

I don't think the problem is in your code. I think it's a bug that recently popped up. A quick google search for this issue turned up this: http://discussions.apple.com/thread.jspa?threadID=2453797&amp;start=0&amp;tstart=0

regulus6633
Thanks a heap. My Googling was coming up blank.
Naym
A: 

Thank you for identifying that thread. I was sure it is an Apple bug but was going mad with my searches not showing anything. Wrong terms I guess.

Naym