使用带有Mail的Apple Scripting桥发送附件会导致邮件背景变黑

时间:2010-06-16 03:21:42

标签: cocoa xcode macos scripting-bridge

当我使用Apple Scripting Bridge发送带附件的邮件时,邮件的背景设置为黑色,这是一个问题,因为文本也是黑色的。有问题的代码是:

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];

背景颜色的实际更改发生在倒数第二行,即:

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

上面的代码部分基本上取自Apple的SBSendMail示例代码。在这个阶段,我真的只进行了必要的更改,以便与我的应用程序中的数据集成。如果我在从Apple新下载之后构建并运行SBSendMail示例,则消息背景也会变为黑色并执行相同的行。附加哪种类型的文件,它所在的位置或使用的计算机或操作系统似乎无关紧要。

这可能是Apple脚本桥中的一个错误,但有没有人遇到过这个问题并找到了解决方案?或者,有没有人知道是否可以使用脚本桥更改MailOutgoingMessage实例的背景颜色?

1 个答案:

答案 0 :(得分:1)

我认为问题不在您的代码中。我认为这是最近出现的一个错误。快速谷歌搜索此问题出现了这个问题:http://discussions.apple.com/thread.jspa?threadID=2453797&start=0&tstart=0