// // KMMailHelper.m // PDF Reader // // Created by HuFeng on 13-3-13. // Copyright (c) 2013年 zhangjie. All rights reserved. // #import "KMMailHelper.h" @implementation KMMailHelper + (void)sendFileWithPaths:(NSArray *)paths { NSString *totalFileString = nil; for (int i = 0; i < [paths count]; i++) { NSString* filePath = [[paths objectAtIndex:i] lastPathComponent]; if (i == 0) { totalFileString = [NSString stringWithFormat:@"%@",filePath]; }else{ totalFileString = [totalFileString stringByAppendingFormat:@" %@",filePath]; } } NSString *emailString = [NSString stringWithFormat:@"\ tell application \"Mail\"\n\ set newMessage to make new outgoing message with properties {subject:\"%@\" & return} \n\ tell newMessage\n\ set visible to true\n\ tell content\n\ ",totalFileString]; //add attachments to script for (NSString *file in paths) { emailString = [emailString stringByAppendingFormat:@"make new attachment with properties {file name:\"%@\"} at before the first paragraph\n", file]; } NSDictionary *errorDictionary; emailString = [emailString stringByAppendingFormat:@"end tell\n activate\n end tell\n end tell"]; NSAppleScript *emailScript = [[NSAppleScript alloc] initWithSource:emailString]; NSAppleEventDescriptor *eventDescriptor = [emailScript executeAndReturnError:&errorDictionary]; if (!eventDescriptor) { NSURL *url = [NSURL URLWithString:@"https://www.pdfreaderpro.com/contact"]; if(![[NSWorkspace sharedWorkspace] openURL:url]) NSLog(@"Failed to open url: %@",[url description]); } } + (void)newEmailWithContacts:(NSString*)contact andSubjects:(NSString*)subjects { NSString *emailString = [NSString stringWithFormat:@"\ tell application \"Mail\"\n\ set newMessage to make new outgoing message with properties {subject:\"%@\" & return} \n\ tell newMessage\n\ set visible to true\n\ make new to recipient at end of to recipients with properties {address:\"%@\"}\n\ tell content\n\ ",subjects,contact]; NSDictionary *errorDictionary; emailString = [emailString stringByAppendingFormat:@"end tell\n activate\n end tell\n end tell"]; NSAppleScript *emailScript = [[NSAppleScript alloc] initWithSource:emailString]; NSAppleEventDescriptor *eventDescriptor = [emailScript executeAndReturnError:&errorDictionary]; if (!eventDescriptor) { NSURL *url = [NSURL URLWithString:@"https://www.pdfreaderpro.com/contact"]; if(![[NSWorkspace sharedWorkspace] openURL:url]) NSLog(@"Failed to open url: %@",[url description]); } } @end