2012-08-20 4 views
1

Я новичок в этой теме может помочь мне ...Iphone-операция не может быть завершена

я посылаю информацию о пользователе на сервер SMTP с помощью Skpsmtpmessage класса. но я получаю: «Операция не может быть завершена». в -(void)messageFailed:(SKPSMTPMessage *)message error:(NSError *)error)

Пожалуйста, помогите мне.

- (void) sendMessage { 

    SKPSMTPMessage *testMsg = [[SKPSMTPMessage alloc] init]; 

    NSString *myString; 

    testMsg.relayHost = @"smtp.gmail.com"; 
    testMsg.requiresAuth = YES; 
    testMsg.login = @"my gmail id"; 

    testMsg.pass = @"my gmail password"; 

    testMsg.subject = [NSString stringWithFormat:@"CLIENT iPhone App - %@", self.navigationItem.title]; 
    testMsg.bccEmail = emailField.text; 
    testMsg.wantsSecure = YES; // smtp.gmail.com doesn't work without TLS! 
    testMsg.fromEmail = emailField.text; 
    NSString *ff = [[UIDevice currentDevice] uniqueIdentifier]; 
    NSString *gg = [[UIDevice currentDevice] model]; 
    NSString *hh = [[UIDevice currentDevice] localizedModel]; 
    NSString *ii = [[UIDevice currentDevice] name]; 
    NSString *jj = [[UIDevice currentDevice] systemName]; 
    NSString *kk = [[UIDevice currentDevice] systemVersion]; 
    NSString *path; 
    if ([self.navigationItem.title isEqualToString:@"Request Authorization"]) 
    { 
     path = [[NSBundle mainBundle] pathForResource:@"ThankYou" ofType:@"txt"]; 
     testMsg.toEmail = @"[email protected]"; 
    } 
    else 
    { 
     path = [[NSBundle mainBundle] pathForResource:@"ThankYou2" ofType:@"txt"]; 
     testMsg.toEmail = @"[email protected]"; 
    } 

    NSString *fileText = [NSString stringWithContentsOfFile:path]; 
    myString = [NSString stringWithFormat:@"LEADERS %@-\n\n%@\n\nName: %@\nCompany: %@\nAddress: %@\nCity: %@\nState: %@\nZip: %@\nPhone: %@\nFax: %@\nEmail: %@\nComments: %@\nRequire New Merchant Account: %@\nReferral Code: %@\nIdentifier: %@\nModel: %@\nLocalized Model: %@\nName: %@\nSystem Name: %@\nSystem Version: %@",self.navigationItem.title,fileText, firstNameField.text,companyField.text,addressField.text,cityField.text,stateField.text,zipCodeField.text,phoneField.text,faxField.text,emailField.text,countryField.text,customerIdField.text,lastNameField.text,ff,gg,hh,ii,jj,kk]; 

    NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:@"text/plain",kSKPSMTPPartContentTypeKey, 
          myString,kSKPSMTPPartMessageKey,@"8bit",kSKPSMTPPartContentTransferEncodingKey,nil]; 

    testMsg.parts = [NSArray arrayWithObjects:plainPart,nil,nil]; 
    testMsg.delegate= self; 

    [testMsg send]; 

    [self.navigationController popViewControllerAnimated:TRUE]; 
} 

ответ

0
-(void)sendMail 
{ 
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 

    SKPSMTPMessage *testMsg = [[SKPSMTPMessage alloc] init]; 
    testMsg.fromEmail = [defaults objectForKey:@"fromEmail"]; 

    testMsg.toEmail = [defaults objectForKey:@"toEmail"]; 
    testMsg.bccEmail = [defaults objectForKey:@"bccEmal"]; 
    testMsg.relayHost = [defaults objectForKey:@"relayHost"]; 

    testMsg.requiresAuth = [[defaults objectForKey:@"requiresAuth"] boolValue]; 

    NSLog(@"%@",testMsg.fromEmail); 

    if (testMsg.requiresAuth) 
    { 
     testMsg.login = [defaults objectForKey:@"login"]; 
     testMsg.pass = [defaults objectForKey:@"pass"]; 
    } 

    testMsg.wantsSecure = [[defaults objectForKey:@"wantsSecure"] boolValue]; // smtp.gmail.com doesn't work without TLS! 

    testMsg.subject = @"SMTPMessage Test Message"; 

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

    testMsg.delegate = self; 

    NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:@"text/plain",kSKPSMTPPartContentTypeKey, 
           @"This is a tést messåge.",kSKPSMTPPartMessageKey,@"8bit",kSKPSMTPPartContentTransferEncodingKey,nil]; 

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 

    NSString *documentsDirectory = [paths objectAtIndex:0]; 

    NSString *getImagePath = [documentsDirectory stringByAppendingPathComponent:@"savedImage.jpg"]; 

    NSData *jpgData = [NSData dataWithContentsOfFile:getImagePath]; 

    NSDictionary *jpgPart = [NSDictionary dictionaryWithObjectsAndKeys:@"text/directory;\r\n\tx-unix-mode=0644;\r\n\tname=\"savedImage.jpg\"",kSKPSMTPPartContentTypeKey, 
           @"attachment;\r\n\tfilename=\"savedImage.jpg\"",kSKPSMTPPartContentDispositionKey,[jpgData encodeBase64ForData],kSKPSMTPPartMessageKey,@"base64",kSKPSMTPPartContentTransferEncodingKey,nil]; 

    testMsg.parts = [NSArray arrayWithObjects:plainPart,jpgPart,nil]; 

    [testMsg send]; 


} 

- (void)messageSent:(SKPSMTPMessage *)message 
{ 
    UIAlertView *alertView = [[UIAlertView alloc] 
           initWithTitle:@"SMTP Mail" 
           message:@"Yay! Message was sent!" 
           delegate:nil 
           cancelButtonTitle:@"OK" 
           otherButtonTitles:nil, 
           nil]; 
    [alertView show]; 
    [alertView release]; 
    [message release]; 
} 

- (void)messageFailed:(SKPSMTPMessage *)message error:(NSError *)error 
{ 
    NSString *str = [NSString stringWithFormat:@"Darn! Error!\n%i: %@\n%@", [error code], [error localizedDescription], [error localizedRecoverySuggestion]]; 
    UIAlertView *alertView = [[UIAlertView alloc] 
           initWithTitle:@"SMTP Mail" 
           message:str 
           delegate:nil 
           cancelButtonTitle:@"OK" 
           otherButtonTitles:nil, 
           nil]; 
    [alertView show]; 
    [alertView release]; 
    [message release]; 
} 
0

мы должны отправить почту с помощью

-(void)sendMail 
{ 
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 

    SKPSMTPMessage *testMsg = [[SKPSMTPMessage alloc] init]; 
    testMsg.fromEmail = [defaults objectForKey:@"fromEmail"]; 

    testMsg.toEmail = [defaults objectForKey:@"toEmail"]; 
    testMsg.bccEmail = [defaults objectForKey:@"bccEmal"]; 
    testMsg.relayHost = [defaults objectForKey:@"relayHost"]; 

    testMsg.requiresAuth = [[defaults objectForKey:@"requiresAuth"] boolValue]; 

    NSLog(@"%@",testMsg.fromEmail); 

    if (testMsg.requiresAuth) 
    { 
     testMsg.login = [defaults objectForKey:@"login"]; 
     testMsg.pass = [defaults objectForKey:@"pass"]; 
    } 

    testMsg.wantsSecure = [[defaults objectForKey:@"wantsSecure"] boolValue]; 
    // smtp.gmail.com doesn't work without TLS! 

    testMsg.subject = @"SMTPMessage Test Message"; 

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

    testMsg.delegate = self; 

    NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:@"text/plain", kSKPSMTPPartContentTypeKey, @"This is a tést messåge.", kSKPSMTPPartMessageKey, @"8bit", kSKPSMTPPartContentTransferEncodingKey, nil]; 

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 

    NSString *documentsDirectory = [paths objectAtIndex:0]; 

    NSString *getImagePath = [documentsDirectory stringByAppendingPathComponent:@"savedImage.jpg"]; 

    NSData *jpgData = [NSData dataWithContentsOfFile:getImagePath]; 

    NSDictionary *jpgPart = [NSDictionary dictionaryWithObjectsAndKeys:@"text/directory;\r\n\tx-unix-mode=0644;\r\n\tname=\"savedImage.jpg\"",kSKPSMTPPartContentTypeKey, @"attachment;\r\n\tfilename=\"savedImage.jpg\"",kSKPSMTPPartContentDispositionKey,[jpgData encodeBase64ForData],kSKPSMTPPartMessageKey,@"base64",kSKPSMTPPartContentTransferEncodingKey,nil]; 

    testMsg.parts = [NSArray arrayWithObjects:plainPart,jpgPart,nil]; 

    [testMsg send]; 
} 
+0

теперь я получаю другую ошибку как "не logot" в - (пустоте) messageFailed: (SKPSMTPMessage *) сообщение об ошибке: (NSError *) ошибка вы могли бы помочь мне ... –