objective-c - 用于发送电子邮件的脚本桥 - 错误 : Object not added to container yet

标签 objective-c macos email scripting-bridge

我们正在使用 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]

如果您能帮助我们解决此问题或提供替代解决方案,我们将不胜感激!

谢谢 约翰

最佳答案

从 Mojave 开始,您需要向用户解释为什么您要求访问 AppleScript。为此,请将其添加到您的 Info.plist 中:

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

Daniel Jalkut 写道 a good blog post在 Mojave 处于测试阶段时关于此问题。

关于objective-c - 用于发送电子邮件的脚本桥 - 错误 : Object not added to container yet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57346621/

相关文章:

java - 具有列 : Remove alternating background coloring for rows on Linux/Mac 的 SWT 树

Java Mail API,有什么方法可以确定邮件是否已送达?

html - 无法调试 Gmail Mobile 的电子邮件模板

ios - NSKeyedArchiver 和 Apple 上传

python - 调用 fork() 时,多处理导致 Python 崩溃并给出错误可能已在另一个线程中进行

objective-c - 无法访问 settings.bundle xcode 4?

ios - 为什么 Cocoapods 将 HockeyMac-SDK 添加到我的 iOS 目标?

python - 从移动设备发送的电子邮件被奇怪地使用电子邮件库解码

ios - NSMutableArray 转换为自定义类型的快速数组

objective-c - 如何在 Objective-c 中将数组声明为常量?