views:

64

answers:

1

I am using the following code to send the mail but when i click on the send button, it come out of the app and send the mail. i dont want to come out of my application.

  -(IBAction) done:(id) sender 
   {
[self sendEmailTo: @"[email protected]" withSubject: @" Question" 
    withBody:[textbody text]];

}

 - (void) sendEmailTo:(NSString *)to withSubject:(NSString *) subject withBody:(NSString *)body 

   {
      NSString *mailString = [NSString stringWithFormat:@"mailto:?to=%@&subject=%@&body=%@",
                        [to stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding],
                        [subject stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding],
                        [body  stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]];

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:mailString]];
 }


    can any one have the solution for this ?
+1  A: 

You probably want to look into MFMailComposeViewController - it's the best option for that after the release of iPhone OS 3.0 software.

If you don't want a UI, you need to implement the SMTP protocol, since I don't think there's a built in one. But there is a google code project that provides this, if you want to incorporate it in your app.

LBushkin