如何解决使用Cocoa Scripting Bridge发送电子邮件而无需事先知道收件人
| 我正在使用默认的Apple提供的SBSendEmail示例代码发送电子邮件。我的情况唯一的区别是我事先不知道收件人,我希望用户在“邮件的收件人”窗口中输入收件人。这是我的代码: MailApplication *mail = [SBApplication
applicationWithBundleIdentifier:@\"com.apple.Mail\"];
/* create a new outgoing message object */
MailOutgoingMessage *emailMessage =
[[[mail classForScriptingClass:@\"outgoing message\"] alloc]
initWithProperties:
[NSDictionary dictionaryWithObjectsAndKeys:
@\"this is my subject\",@\"subject\",@\"this is my content\",@\"content\",nil]];
/* add the object to the mail app */
[[mail outgoingMessages] addObject: emailMessage];
/* set the sender,show the message */
// emailMessage.sender = [self.fromField stringValue];
emailMessage.visible = YES;
/* create a new recipient and add it to the recipients list */
// MailToRecipient *theRecipient =
// [[[mail classForScriptingClass:@\"to recipient\"] alloc]
// initWithProperties:
// [NSDictionary dictionaryWithObjectsAndKeys:
// @\"recipientEmailHere@example.com\",@\"address\",// nil]];
// [emailMessage.toRecipients addObject: theRecipient];
/* add an attachment,if one was specified */
NSString *attachmentFilePath = \"<my provided file path>\";
if ( [attachmentFilePath length] > 0 ) {
/* create an attachment object */
MailAttachment *theAttachment = [[[mail
classForScriptingClass:@\"attachment\"] alloc]
initWithProperties:
[NSDictionary dictionaryWithObjectsAndKeys:
attachmentFilePath,@\"fileName\",nil]];
/* add it to the list of attachments */
[[emailMessage.content attachments] addObject: theAttachment];
}
/* send the message */
[emailMessage send];
由于我尚未指定收件人,因此邮件应用程序将打开一个警报,提示错误,您尚未指定任何收件人。尽管此警报只有一个按钮“编辑邮件”,然后用户可以使用该按钮添加收件人。此警报可能无法打开吗?
解决方法
你可以试试
[emailMessage open];
这将导致Mail.app在撰写窗口中打开您的邮件。
要使Mail.app成为最前端的应用程序,以便用户可以看到新创建的消息窗口,请使用:
[mail activate];
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。