Using the Apple Scripting bridge with Mail to send an attachment causes the message background to go
Posted
by Naym
on Stack Overflow
See other posts from Stack Overflow
or by Naym
Published on 2010-06-16T03:21:42Z
Indexed on
2010/06/16
7:52 UTC
Read the original article
Hit count: 332
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.
© Stack Overflow or respective owner