title: Show waiting view when sending mail using smtp connection ios?
body: <p>I am working on a app in which I am sending mail using mail-core engine. I have created my own viewController to send mail. I want to show a waiting view when mail sending is in process. My waiting view always displays after mail sending has been done. Is it some kind of threading issue?</p>
  
  <p>Here is the code which I'm using to send mail.</p>
  
  <pre><code>- (IBAction) sendTapped:(id) sender {
  
  [txtfSubject resignFirstResponder];
  [txtfReceptient resignFirstResponder];
  [txtvMessageBody resignFirstResponder];
  
  [self setTo:txtfReceptient.text];
  [self setFrom:username];
  [self setSubject:txtfSubject.text];
  [self setBody:txtvMessageBody.text];
  
  [self performSelector:@selector(prepareAndSendMail) withObject:nil afterDelay:0.34];
  }
  
  
  - (void) prepareAndSendMail {
  
  
  [WNAppDelegate performSelectorOnMainThread:@selector(showWaitingView) withObject:nil waitUntilDone:NO];
  
  //TODO: send mail here
  CTCoreMessage *msg = [[CTCoreMessage alloc] init];
  [msg setTo:[myMessage to]];
  [msg setFrom:[myMessage from]];
  
  //Encode message here
  NSString *encodedMessage = nil;
  
  @try {
      encodedMessage = [self encodeMessage:txtvMessageBody.text];
  }
  @catch (NSException * e) {
      NSLog(@"An exception occurred while encoding message");
  }
  @finally {
      if(encodedMessage){
          [msg setBody:encodedMessage];
      }
  }
  
  [msg setSubject:[myMessage subject]];
  
  BOOL success =  [self sendMailOnAnotherThread:msg];
  
  [msg release];
  
  [WNAppDelegate performSelectorOnMainThread:@selector(removeWaitingView) withObject:nil waitUntilDone:NO];
  //[appDelegate removeWaitingView];
  if(!success) {
      UIAlertView * empty_alert = [[UIAlertView alloc] initWithTitle:@"Error"
                                                             message:@"Could not send." 
                                                            delegate:nil 
                                                   cancelButtonTitle:@"OK" 
                                                   otherButtonTitles:nil];
      [empty_alert show];
      [empty_alert autorelease];
      return;
  }   
  else {
      //Message sent successfully
      if(self.target &amp;&amp; [self.target respondsToSelector:@selector(messageSentSuccessfully)]){
          [self.target messageSentSuccessfully];
      }
  
      WN_POST_NOTIFICATION(kMessageSentSuccessfully,nil);
  }
  
  [self dismissModalViewControllerAnimated:YES];  
   }
  
  - (BOOL) sendMailOnAnotherThread:(CTCoreMessage*)message {
  
  
  BOOL success = YES;
  
  BOOL auth = YES;
  BOOL tls = YES;
  
  @try {
      [CTSMTPConnection sendMessage:message server:GMAIL_SERVER  username:username
                           password:password port:GMAIL_PORT_Number useTLS:tls useAuth:auth];
  }
  @catch (NSException * e) {
      //Msg failed to send;
      success = FALSE;
  }
  return success;     
  }
  </code></pre>