在iphone sdk中通过正文在后台发送电子邮件

在iphone sdk中通过正文在后台发送电子邮件,iphone,Iphone,我正在开发的应用程序,我想在后台发送电子邮件。 为此,我使用了SKPSMTP库,但当我收到邮件时,它没有正文,所以任何人都可以告诉我我的代码哪里错了。 以下是单击按钮时的代码 - (void)sendMessageInBack:(id)anObject { if(![self validateEmail:txt_email.text]) { if([txt_email.text isEqualToString:@""] ) {

我正在开发的应用程序,我想在后台发送电子邮件。 为此,我使用了SKPSMTP库,但当我收到邮件时,它没有正文,所以任何人都可以告诉我我的代码哪里错了。 以下是单击按钮时的代码

- (void)sendMessageInBack:(id)anObject
{
    if(![self validateEmail:txt_email.text])
    {
        if([txt_email.text isEqualToString:@""] )
        {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Mandatory field" message:@"Please fill complete email" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
            [alert show];
            [alert release];
        }
        else
        {
            if(self.interfaceOrientation==UIInterfaceOrientationLandscapeLeft || self.interfaceOrientation==UIInterfaceOrientationLandscapeRight ) 
            {
                if(rotate)
                [btn_Send setImage:[UIImage imageNamed:@"send_button.png"] forState:UIControlStateNormal];
            }
            else if(self.interfaceOrientation==UIInterfaceOrientationPortrait || self.interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown )
            {
                if(rotate)
                [btn_Send setImage:[UIImage imageNamed:@"send button1.png"] forState:UIControlStateNormal];

            }   

                NSLog(@"Start Sending");
                NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
                NSString *documentsDirectory = [paths objectAtIndex:0];
                NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"RequestReview.txt"];

                NSData *dataObj = [NSData dataWithContentsOfFile:writableDBPath];
                //NSString *mailid;
                SKPSMTPMessage *testMsg = [[SKPSMTPMessage alloc] init];
                testMsg.fromEmail =@"spymekdemo@gmail.com";
                testMsg.toEmail = @"priyanka.chinchmalatpure@gmail.com";// txtEmail.text;
                testMsg.relayHost = @"smtp.gmail.com";
                testMsg.requiresAuth = YES;
                testMsg.login = @"spymekdemo@gmail.com";
                testMsg.pass =@"spymek123";
                testMsg.subject =@"Sbject"; //[NSString stringWithFormat:@"Reply to Review From %@", txtName.text];
                testMsg.wantsSecure = YES; // smtp.gmail.com doesn't work without TLS!

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

                NSString *deviceIdentifier=[NSString stringWithFormat:@"%@",[[UIDevice currentDevice]uniqueIdentifier]];//[NSString stringWithFormat:@"%@",deviceToken.uniqueIdentifier];
                NSLog(@"%@",deviceIdentifier);

                //NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:@"text/plain",kSKPSMTPPartContentTypeKey,
                //                             [NSString stringWithFormat:@"Request Review\n\nDevice Identifier=%@\nProduct Name=%@\nProduct Download URL=%@\nUser Name=%@\nEmail=%@\nPromo Code=%@\nDescription Of Product=%@\n\n\n", deviceIdentifier, txtProduct.text,txtDownloadURL.text, txtName.text,txtEmail.text,txtPromocode.text, txtDescription.text]
                //                             ,kSKPSMTPPartMessageKey,@"8bit",kSKPSMTPPartContentTransferEncodingKey,nil];

                NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:@"text/html",kSKPSMTPPartContentTypeKey,
                                           [NSString stringWithFormat:@"<h2>Request Review</h2><br/><br/><b>Thank you for giving us your review</b> <br/>Device Identifier=%@<br/>Product Name=<br/>Product Download URL=<br/>User Name=<br/>Email=<br/>Promo Code=<br/>Description Of Product=<br/><br/><br/>", deviceIdentifier]
                                           ,kSKPSMTPPartMessageKey,@"8bit",kSKPSMTPPartContentTransferEncodingKey,nil];


                //   [NSString stringWithFormat:@"<h3>Review App</h3> <br/> <br/><b>Name=%@<b><br/> <br/>,\n<u>Email=%@</u><br/> <br/>,\nPassword=%@,<br/><br/> <b>\nComments=%@\n\n</b><br/>",txtName.text,txtMailId.text, txtPassword.text, txtComment.text],kSKPSMTPPartMessageKey,@"8bit",kSKPSMTPPartContentTransferEncodingKey,nil];

                // @"<html><body><h1>Review App</h1> <br/> <b>Some text to include in body</b></body></html>"
                NSDictionary *vcfPart = [NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"text/directory;\r\n\tx-unix-mode=0644;\r\n\tname=\"%@.txt\"",txt_name.text],kSKPSMTPPartContentTypeKey,
                                         [NSString stringWithFormat:@"attachment;\r\n\tfilename=\"%@.txt\"",txt_name.text],kSKPSMTPPartContentDispositionKey,[dataObj encodeBase64ForData],kSKPSMTPPartMessageKey,@"base64",kSKPSMTPPartContentTransferEncodingKey,nil];


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

                [testMsg send];
        }       
    }

    rotate=YES; 
}

- (void)messageFailed:(SKPSMTPMessage *)message error:(NSError *)error
{
        [message release];
                //open an alert with just an OK button
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Unable to send email"
                                                               delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
        [alert show];   
        [alert release];
        NSLog(@"delegate - error(%d): %@", [error code], [error localizedDescription]);
                //[self ClearFile];
                //UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Request Review" message:@"Review Posting failed.. Try Again Later.." delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Done",nil];
}


- (void)messageSent:(SKPSMTPMessage *)message
    {
    [message release];

    NSLog(@"delegate - message sent");
}

你有没有试过发送一个简单的信息,比如Hello?那些HTML标签可能会弄乱它。嗨,Priyanka。。你的问题解决了吗?我们可以在后台发送电子邮件吗?