Friday, September 30, 2011

sending email in obj-c

in.h


import MessageUI/MessageUI.h


delegate  MFMailComposeViewControllerDelegate

 - (void)openInAppEmail:(NSArray*)recipients
           mailSubject:(NSString*)mailSubject
              mailBody:(NSString*)mailBody
                isHtml:(BOOL)isHtml;
 ##########################################
in .m



- (IBAction)mail:(id)sender {
   
   
   
   
        // SMS *   start = [[SMS  alloc] initWithNibName:@"SMS" bundle:[NSBundle mainBundle]];
        //start.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
        // start.modalPresentationStyle = UIModalPresentationFormSheet;
        // [self presentModalViewController:start animated:YES];
    email=@"hi@hi.com";
   
    [self openInAppEmail:[NSArray arrayWithObject:email] mailSubject:@"" mailBody:@"" isHtml:YES];
   
   
   
   
   
}


- (void)openInAppEmail:(NSArray*)recipients
           mailSubject:(NSString*)mailSubject
              mailBody:(NSString*)mailBody
                isHtml:(BOOL)isHtml
{
    MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
    controller.mailComposeDelegate = self;
    [controller setToRecipients:recipients];
    [controller setSubject:mailSubject];
    [controller setMessageBody:mailBody isHTML:isHtml];
    [self presentModalViewController:controller animated:YES];
}

- (void)mailComposeController:(MFMailComposeViewController*)controller
          didFinishWithResult:(MFMailComposeResult)result
                        error:(NSError*)error {
    [self dismissModalViewControllerAnimated:YES];
}

No comments:

FEEDJIT Live