Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

iphone

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];
    }

}
like image 430
Ted pottel Avatar asked Feb 26 '14 01:02

Ted pottel


2 Answers

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

#import <MessageUI/MessageUI.h>
like image 118
Amrendra Pratap Singh Avatar answered Oct 18 '22 05:10

Amrendra Pratap Singh


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
like image 36
yakattack Avatar answered Oct 18 '22 05:10

yakattack