2012-10-07 28 views
0

我試圖用「SKPSMTPMessage」在iPhone發送郵件和我加了庫,誤差發送郵件(kSKPSMTPPartMessageKey爲零)

在我的課,我添加以下代碼:

- (IBAction)sendMail:(id)sender 
{ 
// if there are a connection 
if ([theConnection isEqualToString:@"true"]) { 
    if ([fromEmail.text isEqualToString:@""] || [toEmail.text isEqualToString:@""]) { 
     UIAlertView *warning = [[UIAlertView alloc] initWithTitle:@"تحذير" message:@"لم يتم ادخال جميع المجالات" delegate:self cancelButtonTitle:@"موافق" otherButtonTitles:nil, nil]; 
     [warning show]; 
    }else { 

     SKPSMTPMessage *test_smtp_message = [[SKPSMTPMessage alloc] init]; 
     test_smtp_message.fromEmail = fromEmail.text; 
     test_smtp_message.toEmail = toEmail.text; 
     test_smtp_message.relayHost = @"smtp.gmail.com"; 
     test_smtp_message.requiresAuth = YES; 
     test_smtp_message.login = @"[email protected]"; 
     test_smtp_message.pass = @"myPass"; 
     test_smtp_message.wantsSecure = YES; 

     NSString *subject= @"Suggest a book for you"; 
     test_smtp_message.subject = [NSString stringWithFormat:@"%@ < %@ > ",fromEmail.text, subject]; 
     test_smtp_message.delegate = self; 

     NSMutableArray *parts_to_send = [NSMutableArray array]; 


     NSDictionary *plain_text_part = [NSDictionary dictionaryWithObjectsAndKeys: 
             @"text/plain\r\n\tcharset=UTF-8;\r\n\tformat=flowed", kSKPSMTPPartContentTypeKey, 
             [messageBody.text stringByAppendingString:@"\n"], kSKPSMTPPartMessageKey, 
             @"quoted-printable", kSKPSMTPPartContentTransferEncodingKey, 
             nil]; 
     [parts_to_send addObject:plain_text_part]; 

     // to send attachment 

     NSString *image_path = [[NSBundle mainBundle] pathForResource:BookCover ofType:@"jpg"]; 
     NSData *image_data = [NSData dataWithContentsOfFile:image_path];   
     NSDictionary *image_part = [NSDictionary dictionaryWithObjectsAndKeys: 
            @"inline;\r\n\tfilename=\"image.png\"",kSKPSMTPPartContentDispositionKey, 
            @"base64",kSKPSMTPPartContentTransferEncodingKey, 
            @"image/png;\r\n\tname=Success.png;\r\n\tx-unix-mode=0666",kSKPSMTPPartContentTypeKey, 
            [image_data encodeWrappedBase64ForData],kSKPSMTPPartMessageKey, 
            nil]; 


     [parts_to_send addObject:image_part]; 



     test_smtp_message.parts = parts_to_send; 

     Spinner.hidden = NO; 
     [Spinner startAnimating]; 
     ProgressBar.hidden = NO; 
     HighestState = 0; 

     [test_smtp_message send]; 

    } 

}else { 
    UIAlertView *alertNoconnection = [[UIAlertView alloc] initWithTitle:@"تحذير" message:@"لا يوجد شبكة " delegate:self cancelButtonTitle:@"الغاء" otherButtonTitles:nil, nil]; 
    [alertNoconnection show]; 
} 
} 

但是當我試圖把它給了我以下異常:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFString appendString:]: nil argument' 

,並在SKPSMTPMessage.m強調此行

[message appendString:[part objectForKey:kSKPSMTPPartMessageKey]]; 

和我不明白什麼是零確切 誰能幫我解決這個問題? 在此先感謝。

回答

0

我找到了解決辦法,這個問題是因爲是IMAGE_DATA空,我被取代了它:

 NSString *image_path = [NSString stringWithFormat:@"%@/%@",[[NSBundle mainBundle] bundlePath],[NSString stringWithFormat:@"%@.jpg",BookCover]]; 

     NSString *imgLink = [NSString stringWithFormat:@"http://iktab.com/global/modules/bookstore/files/book_cover_photo/%@",BookCover]; 

     NSString *urlString = [imgLink stringByReplacingOccurrencesOfString:@" " withString:@"%20"]; 

     NSURL *url = [NSURL URLWithString:urlString]; 

     NSData* image_data = [NSData dataWithContentsOfURL:url];