Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8344051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:14:53+00:00 2026-06-09T06:14:53+00:00

I have an app which uses MFMailComposeViewController to send documents through email. I read

  • 0

I have an app which uses MFMailComposeViewController to send documents through email. I read somewhere that I need to enable at least one email so that the method [MFMailComposeViewController canSendEmail] will return YES and email the document. However, whenever I tap the email button, all it does is return to the previous view.

I checked the code and [MFMailComposeViewController canSendEmail] returns NO. Can anyone tell me why is this happening?

Here is the code:

- (void)sendEmail
{
   if ([MFMailComposeViewController canSendMail] == NO) return;
   NSURL *fileURL = document.fileURL; NSString *fileName = document.fileName;

   NSData *attachment = [NSData dataWithContentsOfURL:fileURL options:(NSDataReadingMapped|NSDataReadingUncached) error:nil];

        if (attachment != nil) 
        {
            MFMailComposeViewController *mailComposer = [MFMailComposeViewController new];

            [mailComposer addAttachmentData:attachment mimeType:@"application/pdf" fileName:fileName];

            [mailComposer setSubject:fileName]; 

            mailComposer.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
            mailComposer.modalPresentationStyle = UIModalPresentationFormSheet;

            mailComposer.mailComposeDelegate = self; 

            [self presentModalViewController:mailComposer animated:YES];

            [mailComposer release];
        }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T06:14:54+00:00Added an answer on June 9, 2026 at 6:14 am

    First add and Import the MessageUI Framework

    #import <MessageUI/MessageUI.h>
    

    and Declare the MFMaileComposeViewControllerDelegate

    @interface MailViewController : UIViewController <MFMailComposeViewControllerDelegate>
    

    Write this code for sending the mail

    - (IBAction)openMail:(id)sender 
    {
    if ([MFMailComposeViewController canSendMail])
    {
        MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
    
        mailer.mailComposeDelegate = self;
    
        [mailer setSubject:@"xyz"];
    
        NSArray *toRecipients = [NSArray arrayWithObjects:@"fisrtMail@example.com", @"secondMail@example.com", nil];
        [mailer setToRecipients:toRecipients];
    
    
        NSData *pdfdata = [NSData dataWithContentsOfURL:"Your URL"]
    
        [mailController addAttachmentData:pdfData
                                 mimeType:@"application/pdf"
                                 fileName:@"file.pdf"];
    
        NSString *emailBody = @"xyz";
    
        [mailer setMessageBody:emailBody isHTML:NO];
    
        [self presentModalViewController:mailer animated:YES];
    
        [mailer release];
    }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure"
                                                        message:@"Your device doesn't support the composer sheet"
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles: nil];
        [alert show];
        [alert release];
    }
    

    }

    and also write the delegate method of MFMailComposeViewControllerDelegate

    - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
    {   
        switch (result)
        {
            case MFMailComposeResultCancelled:
                NSLog(@"Mail cancelled: you cancelled the operation and no email message was queued.");
                break;
            case MFMailComposeResultSaved:
                NSLog(@"Mail saved: you saved the email message in the drafts folder.");
                break;
            case MFMailComposeResultSent:
                NSLog(@"Mail send: the email message is queued in the outbox. It is ready to send.");
                break;
            case MFMailComposeResultFailed:
                NSLog(@"Mail failed: the email message was not saved or queued, possibly due to an error.");
                break;
            default:
                NSLog(@"Mail not sent.");
                break;
        }
    
            // Remove the mail view
        [self dismissModalViewControllerAnimated:YES];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app which uses core data, the database structure was designed through
I have an app which uses a sqlite db, saving it in the Documents
I have an app which uses a keyboard hook procedure in a library. The
I have implemented an App which uses SQLite database, now if I run the
I have made an app which uses DropBox SDK for iPhone to connect to
I have a Django app which uses LDAP as the authentication backend. I'm not
I have a Silverlight web app which uses ASP.net Website administration tool for user
I have made a layout for my app which uses a lot of activities.
I have a Rails 3.1.3 app which uses devise for users authentication and soft-deletes
I have finished the development of my app which uses Google Maps. During the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.