Ted pottel
Ted pottel

Reputation: 6983

Trying to send email, getting "use of undeclared unidentified MFMailComposeViewController"

I'm trying to send a email message in my app. I'm trying to use the MFMailComposeViewController object, but getting a error message saying its a "undeclared identifier"

code:

-(IBAction) aContact: (id) sender;
{


    if([MFMailComposeViewController canSendMail]){

        MFMailComposeViewController *mailCtrl = [[[MFMailComposeViewController alloc] init] autorelease];
        [mailCtrl setSubject:@"Your TellaFortune Card Reading"];
        //  [mailCtrl setToRecipients:[NSArray arrayWithObject:@"[email protected]"]];
        mailCtrl.mailComposeDelegate = self;

        NSString *send;
        send=[ NSString stringWithFormat: @"%@ %@",content,@"\n \n By www.TellaFortune.com"];
        [mailCtrl setMessageBody: send  isHTML: false];

        [self presentModalViewController:mailCtrl animated:NO];
        //      [mailCtrl release];

    }
    else
    {
        UIAlertView *alert=[[ UIAlertView alloc]
                            initWithTitle:@"Cannot send email"
                            message: @"Please check internet connection and email set up"
                            delegate: self
                            cancelButtonTitle:@"Ok"
                            otherButtonTitles: nil];

        [alert show];
    }

}

Upvotes: 8

Views: 3774

Answers (2)

yakattack
yakattack

Reputation: 159

For anyone who is using Swift and seeing this message:

First go to your project settings in Xcode, select Build Phases, then Link Binary with Libraries, and add "MessageUI.framework" to your project.

Then, in the Swift file in which you want to use a MFMailComposeViewController or implement the MFMailComposeViewControllerDelegate, add:

import MessageUI

Upvotes: 16

Amrendra Pratap Singh
Amrendra Pratap Singh

Reputation: 661

Import framework "MessageUI.framework" to your project and in your .h file add

#import <MessageUI/MessageUI.h>

Upvotes: 20

Related Questions