2011-10-18 11 views
0

私はskpsmtpmessageライブラリ経由でplistファイルを添付しようとするたびに、適切なそれぞれの名前で電子メールに表示されますが、サイズは0バイトです。ここでskpsmtpmessageを使用してplistファイルを正しく添付する方法は?

-(void) sendMessage{ 

NSLog(@"Start Sending"); 

SKPSMTPMessage *test_smtp_message = [[SKPSMTPMessage alloc] init]; 
test_smtp_message.fromEmail = @"[email protected]"; 
test_smtp_message.toEmail = @"[email protected]"; 
test_smtp_message.relayHost = @"smtp.live.com"; 
test_smtp_message.requiresAuth = YES; 
test_smtp_message.login = @"[email protected]"; 
test_smtp_message.pass = @"blabla"; 
test_smtp_message.wantsSecure = YES; // smtp.gmail.com doesn't work without TLS! 
test_smtp_message.subject = @"An application has crashed!"; 




// test_smtp_message.bccEmail = @"[email protected]"; 

// Only do this for self-signed certs! 
// test_smtp_message.validateSSLChain = NO; 
test_smtp_message.delegate = self; 

NSMutableArray *parts_to_send = [NSMutableArray array]; 

//If you are not sure how to format your message part, send an email to your self. 
//In Mail.app, View > Message> Raw Source to see the raw text that a standard email client will generate. 
//This should give you an idea of the proper format and options you need 
    /*NSDictionary *plain_text_part = [NSDictionary dictionaryWithObjectsAndKeys: 
            @"text/plain\r\n\tcharset=UTF-8;\r\n\tformat=flowed", kSKPSMTPPartContentTypeKey, 
            [@"Sample message body here!" stringByAppendingString:@"\n"], kSKPSMTPPartMessageKey, 
            @"quoted-printable", kSKPSMTPPartContentTransferEncodingKey, 
            nil]; 
    [parts_to_send addObject:plain_text_part];*/ 



    //NSString *image_path = [[NSBundle mainBundle] pathForResource:@"Success" ofType:@"png"]; 
    NSArray *crashList = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:@"/User/Library/Logs/CrashReporter" error:nil]; 
    NSLog(@"CrashList: %@", crashList); 
    if ([crashList count] != 0) 
    { 
     for (int i=0; i < [crashList count]; i++) { 
      NSString *filePath = [NSString stringWithFormat:@"/User/Library/Logs/CrashReporter/%@",[crashList objectAtIndex:i]]; 
      NSData *crashData = [NSData dataWithContentsOfFile:filePath]; 
      NSString *directory = @"text/directory;\r\n\tx-unix-mode=0644;\r\n\tname=\""; 
      directory = [directory stringByAppendingFormat: filePath]; 
      directory = [directory stringByAppendingFormat: @"\""]; 
      NSString *attachment = @"attachment;\r\n\tfilename=\""; 
      attachment = [attachment stringByAppendingFormat: filePath]; 
      attachment = [attachment stringByAppendingFormat: @"\""]; 
      NSDictionary *image_part = [NSDictionary dictionaryWithObjectsAndKeys: 
             directory,kSKPSMTPPartContentTypeKey, 
             attachment,kSKPSMTPPartContentDispositionKey, 
             [crashData encodeBase64ForData],kSKPSMTPPartMessageKey, 
             @"base64",kSKPSMTPPartContentTransferEncodingKey,nil]; 
      /* 
      [NSDictionary dictionaryWithObjectsAndKeys: 
      @"text/directory;\r\n\tx-unix-mode=0644;\r\n\tname=\"test.vcf\"",kSKPSMTPPartContentTypeKey, 
      @"attachment;\r\n\tfilename=\"test.vcf\"",kSKPSMTPPartContentDispositionKey, 
      [vcard_data encodeBase64ForData],kSKPSMTPPartMessageKey, 
      @"base64",kSKPSMTPPartContentTransferEncodingKey,nil]; 

      */ 
      [parts_to_send addObject:image_part]; 
     } 
    } 

test_smtp_message.parts = parts_to_send; 

[test_smtp_message send]; 

} 

電子メールが([email protected]の側)である[GMAIL]

Jared Aaron Loo [email protected] to me 

show details 3:58 PM (39 minutes ago) 
6 attachments — Download all attachments 

    /User/Library/Logs/CrashReporter/LatestCrash-TableViewControl.plist 
0K Import to Contacts Download 
    /User/Library/Logs/CrashReporter/LatestCrash-iSoda.plist 
0K Import to Contacts Download 
    /User/Library/Logs/CrashReporter/LatestCrash.plist 
0K Import to Contacts Download 
    /User/Library/Logs/CrashReporter/TableViewController_09_2011-10-18-104430_Jareds-iPhone.plist 
0K Import to Contacts Download 
    /User/Library/Logs/CrashReporter/TableViewController_09_2011-10-18-104822_Jareds-iPhone.plist 
0K Import to Contacts Download 
    /User/Library/Logs/CrashReporter/iSoda_2011-10-18-105543_Jareds-iPhone.plist 
0K Import to Contacts Download 

すべてのヘルプは非常に高く評価されています。ここでは、コードです! :)

+0

私はここに示したような同様のコードを使用していますが、これまでのところ問題はありません。あなたのコンソール/ログは何を言いますか?たぶん画像が大きすぎますか? – Zammbi

答えて

0

このため、(少なくとも)2つの考えられる原因があります。

NSData *crashData = [NSData dataWithContentsOfFile:filePath]; 

... 
[crashData encodeBase64ForData],kSKPSMTPPartMessageKey, 
... 

は最初のものは、あなたがディスクからファイルを読み取ることができない場合に失敗しても何らかの理由でbase64エンコーディングが失敗した場合、秒は失敗する可能性があります。これらのメソッドのいずれに対してもnil結果の検証を挿入して、エラーを適切に処理してください。

+0

私は、送信時にcrashDataとkSKPSMTPPartMessageKeyの両方がnilではないことを確かめました。私はencodeBase64ForDataをencodeWrappedBase64ForDataで置き換えようとしましたが、無駄です。 –

+0

送受信している生のメールを見ましたか?たぶんそれは手がかりを与えるかもしれない。 –

+0

こんにちは、私は別のサンプルアプリケーションで正確に同じロジックを実装し、それが動作するようです。しかし、それが私のアプリで実装されている場合、それはしません。なぜか分からない= –

関連する問題