objective c - How to send mail from iphone app? -
i try send mail app. want type(dynamically) recipient id,ccid,sub , message.
thanks
senthilkumar
on ios 3+ import #import in view controller header.
then:
-(void)showmailpanel { mfmailcomposeviewcontroller *mailcomposeviewcontroller = [[mfmailcomposeviewcontroller alloc] init]; // on ios < 3 //if ([mfmailcomposeviewcontroller cansendmail] == no) // [self launchmailapp]; // need mailcomposeviewcontroller.mailcomposedelegate = self; [mailcomposeviewcontroller settorecipients:[nsarray arraywithobjects:@"email address1",@"email address 2",nil]]; [mailcomposeviewcontroller setsubject:@"your subject"]; [mailcomposeviewcontroller setmessagebody:@"your body" ishtml:yes]; mailcomposeviewcontroller.delegate = self; [self.navigationcontroller presentmodalviewcontroller:mailcomposeviewcontroller animated:yes]; [mailcomposeviewcontroller release]; } - (void)mailcomposecontroller:(mfmailcomposeviewcontroller*)controller didfinishwithresult:(mfmailcomposeresult)result error:(nserror*)error { // notifies users errors associated interface switch (result) { case mfmailcomposeresultcancelled: nslog(@"result: canceled"); break; case mfmailcomposeresultsaved: nslog(@"result: saved"); break; case mfmailcomposeresultsent: nslog(@"result: sent"); break; case mfmailcomposeresultfailed: nslog(@"result: failed"); break; default: nslog(@"result: not sent"); break; } [controller dismissmodalviewcontrolleranimated:yes]; } -(void)launchmailapp { { nsstring *recipients = @"dest_email"; nsstring *email = [nsstring stringwithformat:@"%@%@", recipients, subject]; email = [email stringbyaddingpercentescapesusingencoding:nsutf8stringencoding]; [[uiapplication sharedapplication] openurl:[nsurl urlwithstring:email]]; }
Comments
Post a Comment