我正在使用默认 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];
由于我没有指定收件人,邮件应用程序会打开一个警报,提示错误,您没有指定任何收件人。尽管此警报只有一个按钮“编辑消息”,但用户可以使用该按钮添加收件人。此警报是否有可能无法打开?