首页 > 解决方案 > 用于发送电子邮件的脚本桥 - 错误:对象尚未添加到容器中

问题描述

我们正在使用 SBSendEmail Apple 代码创建要通过电子邮件应用程序发送的电子邮件。

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

mail.delegate = self;

MailOutgoingMessage *emailMessage = [[[mail    classForScriptingClass:@"outgoing message"] alloc] initWithProperties:
[NSDictionary dictionaryWithObjectsAndKeys:
[self.subjectField stringValue], @"subject",
[[self.messageContent textStorage] string], @"content",
[self.fromField stringValue], @"sender", 
nil]];

[[mail outgoingMessages] addObject: emailMessage];

MailToRecipient *theRecipient = [[[mail classForScriptingClass:@"to recipient"] alloc] initWithProperties:
[NSDictionary dictionaryWithObjectsAndKeys:
[self.toField stringValue], @"address",
nil]];

[emailMessage.toRecipients addObject: theRecipient];
[emailMessage send];

收到此错误:

[General] *** -[SBProxyByCode setSender:]: 对象尚未添加到容器中;选择器无法识别 [self = 0x600000c85bf0]

任何有关使此工作或替代解决方案的帮助将不胜感激!

谢谢约翰

标签: objective-cmacosemailscripting-bridge

解决方案


从 Mojave 开始,您需要向用户说明您要求 AppleScript 访问权限的原因。为此,请将其添加到您的 Info.plist:

<key>NSAppleEventsUsageDescription</key>
<string>MyApp needs to control ___ because ___</string>

在 Mojave 处于测试阶段时,Daniel Jalkut 写了一篇很好的博客文章。


推荐阅读