使用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];
由于我尚未指定收件人,因此邮件应用程序将打开一个警报,提示错误,您尚未指定任何收件人。尽管此警报只有一个按钮“编辑邮件”,然后用户可以使用该按钮添加收件人。此警报可能无法打开吗?
没有找到相关结果
已邀请:
1 个回复
蓄荣糖些
这将导致Mail.app在撰写窗口中打开您的邮件。 要使Mail.app成为最前端的应用程序,以便用户可以看到新创建的消息窗口,请使用: