2016-12-21 4 views
0

Использование Cocoa Scripting Bridge для отправки электронной почты, как я могу добавить больше одного приложения.Использование Cocoa Scripting Bridge для отправки электронной почты

Вот мой код:

MailApplication *mail = [SBApplication applicationWithBundleIdentifier:@"com.apple.Mail"]; 

emailMessageL = [[[mail classForScriptingClass:@"outgoing message"] alloc] initWithProperties: 
NSDictionary dictionaryWithObjectsAndKeys: [self.subjectField stringValue], @"subject", [self.messageContent stringValue], @"content", nil]]; 

[[mail outgoingMessages] addObject: emailMessageL]; 
emailMessageL.sender = [self.fromField stringValue]; 
emailMessageL.visible = YES; 

if ([mail lastError] != nil) 
    return; 

MailToRecipient *theRecipient = [[[mail classForScriptingClass:@"to recipient"] alloc] initWithProperties: 
[NSDictionary dictionaryWithObjectsAndKeys: 
             [self.toField stringValue], @"address", 
             nil]]; 
[emailMessageL.toRecipients addObject: theRecipient]; 

if ([mail lastError] != nil) 
    return; 

NSString *attachmentFilePath = aStrUrl ; 

if ([attachmentFilePath length] > 0) 
{ 
    MailAttachment *theAttachment; 
    theAttachment = [[[mail classForScriptingClass:@"attachment"] alloc] initWithProperties: [NSDictionary dictionaryWithObjectsAndKeys: [[NSURL URLWithString:attachmentFilePath] path], @"fileName", nil]]; 

    [[emailMessageL.content attachments] addObject: theAttachment]; 

    if ([mail lastError] != nil) 
     return; 
} 

ответ

0

Вы заметите, вы добавляете один объект attachments. Это измененный массив, к которому вы можете добавить дополнительные объекты.

Например, я создал четыре текстовых файлов в моем /tmp директории на моем развитии Macintosh и был в состоянии сделать:

for(int index=1; index<4; index++) 
    { 
     NSString *attachmentFilePath = [NSString stringWithFormat: @"/private/tmp/%d.txt", index]; 

     if ([attachmentFilePath length] > 0) 
     { 
      MailAttachment *theAttachment; 
      theAttachment = [[[mail classForScriptingClass:@"attachment"] alloc] initWithProperties: [NSDictionary dictionaryWithObjectsAndKeys: [[NSURL URLWithString:attachmentFilePath] path], @"fileName", nil]]; 

      [emailMessageL.content.attachments addObject: theAttachment]; 

      if ([mail lastError] != nil) 
       return; 
     } 
    } 

Так что в вашем случае, просто addObject: дополнительное вложение, и вы будете просто отлично ,

+0

Большое спасибо за помощь. Проблема полностью решена. Грэзи, Джанни. – Gianni