如何执行“共享到邮件”之类的操作?就像在NSSharingServices
选择邮件时一样。例如,我有NSImage
并且我想达到image2中的结果。我该怎么做?任何指针?
图片1:
图片2:
要仅从文本创建消息,我可以这样做:
NSURL * url;
url = [NSURL URLWithString:@"mailto:"
"?subject="
"&body=text"
];
(void) [[NSWorkspace sharedWorkspace] openURL:url];
但我不知道如何使用图像创建消息。
我找到了一种在使用 ScriptingBridge 框架时添加附件的方法。代码:
MailApplication *mail = [SBApplication
applicationWithBundleIdentifier:@"com.apple.Mail"];
MailOutgoingMessage *emailMessage =
[[[mail classForScriptingClass:@"outgoing message"] alloc]
initWithProperties:
[NSDictionary dictionaryWithObjectsAndKeys:
@"this is my subject", @"subject",
@"this is my content", @"content",
nil]];
[[mail outgoingMessages] addObject: emailMessage];
emailMessage.visible = YES;
NSString *attachmentFilePath = [NSString stringWithUTF8String:"<my provided file path>"];
if ( [attachmentFilePath length] > 0 ) {
MailAttachment *theAttachment = [[[mail
classForScriptingClass:@"attachment"] alloc]
initWithProperties:
[NSDictionary dictionaryWithObjectsAndKeys:
attachmentFilePath, @"fileName",
nil]];
[[emailMessage.content attachments] addObject: theAttachment];
}
[emailMessage visible];
有用。但是如何将 NSImage 添加到附件中?也许我必须将 NSImage 写入临时文件,然后添加为附件并删除临时文件?或者是什么?或者我应该以某种方式将 NSImage 添加到正文中?