0

Possible Duplicate:
how to send email using UIbarbuttonitem without using MFMailComposerViewController

As shown in the image this app used to send mail on send button's click.

I found that it is not showing MFMailComposerViewController.

enter image description here

How can it be possible? How do I get this functionality?

Community
  • 1
  • 1
iPhone
  • 4,092
  • 3
  • 34
  • 58
  • can you edit your question to show the code / action method that gets fired when you click on the "Send" bar button? – Michael Dautermann Nov 22 '11 at 10:09
  • This image is of demo app and I want to implement such kind of functionality in my app. so I don't have any code and knowledge. – iPhone Nov 22 '11 at 10:11
  • Please just edit your original question if you want to provide more context or detail. – Tim Post Nov 22 '11 at 10:29
  • Do I need to present MFMailComposerViewController every time? I don't want to present it. How can I do this? – iPhone Nov 22 '11 at 10:47

2 Answers2

1
- (void)MailButton:(id)sender
{
    if ([MFMailComposeViewController canSendMail]) {
        //atableView.scrollEnabled=YES;
        //[socailNetworkView removeFromSuperview];
    //  self.navigationItem.title = @"Contents";
        MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
        mailViewController.mailComposeDelegate = self;
        [mailViewController setSubject:@""];
        [mailViewController setMessageBody:@"" isHTML:NO];
        NSString *string = [NSString stringWithFormat:@"", nil];


        NSArray *mailArr = [[NSArray alloc] initWithObjects:string,nil];
        [mailViewController setToRecipients:mailArr];
        [self presentModalViewController:mailViewController animated:YES];
        [mailViewController release];

    }

    else {

        NSLog(@"Device is unable to send email in its current state");

    }
}


- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error;

{

    NSLog(@"Mail");
    NSString  *str=@"";
    switch (result) {  
        case MFMailComposeResultCancelled:  
            NSLog(@"Mail send canceled.");  
            str=@"\nMail sending cancelled";
            //msgLabel.text=str;
            //          [msgLabel setFont:[UIFont fontWithName:@"Arial" size:18]];
            //          msgLabel.textColor=[UIColor colorWithRed:(54.0/255.0) green:(2.0/255) blue:(1.0/255) alpha:1.0];

            /* 
             Execute your code for canceled event here ... 
             */  
            break;  
        case MFMailComposeResultSaved:  
            NSLog(@"Mail saved."); 
            str=@"Mail saved";
            /* 
             Execute your code for email saved event here ... 
             */  
            break;  
        case MFMailComposeResultSent:  
            NSLog(@"Mail sent.");  
            str=@"Mail sent";
            /* 
             Execute your code for email sent event here ... 
             */  
            break;  
        case MFMailComposeResultFailed:  
            str=@"Mail not sent";
            NSLog(@"Mail send error: %@.", [error localizedDescription]);  
            /* 
             Execute your code for email send failed event here ... 
             */  
            break;  
        default:  
            break;  
    }
    //alertLabel.text=str;
    //  [viewAlert setBackgroundColor:[UIColor clearColor]];
    //  [self.view addSubview:viewAlert];

    [self dismissModalViewControllerAnimated:YES];
}
Maulik
  • 19,348
  • 14
  • 82
  • 137
Saranya
  • 1,481
  • 3
  • 14
  • 26
1

Sounds like you just need to read a tutorial carefully.

I found this via Google:

New In iPhone 3.0 Tutorial Series, Part 2: In App Email, MessageUI

Yes, it says "iPhone 3.0" but the same concepts and code should work perfectly fine in iOS 5.

Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215