IOS SDK: How to call an email application?

From my iPad app, I would like to call the iPad email app with custom text text. Senders and subject will be empty, the only parameter that I would like to set is the text of the email message. How can i do this?

Thanks!

+6
source share
5 answers

Why not just open the email composer inside your application?

MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init]; [mailController setSubject:@"my subject"]; [mailController setMessageBody:@"my message" isHTML:NO]; mailController.mailComposeDelegate = self; UINavigationController *myNavController = [myViewController navigationController]; if ( mailController != nil ) { if ([MFMailComposeViewController canSendMail]){ [myNavController presentModalViewController:mailController animated:YES]; } } [mailController release]; 
+9
source

Take a look at the MFMailComposeViewController in the Apple documentation. You can use it as follows:

 MFMailComposeViewController *controller=[[MFMailComposeViewController alloc]init]; controller.delegate = self; [controller setMessageBody:<#yourBody#> isHTML:<#isHTML#>]; [self presentModalViewController:controller animated:YES]; [controller release]; 

Remember to add #import <MessageUI/MessageUI.h> to your .h file. It will call methods on your delegate so that you know when it was canceled or a message was sent (successfully or not). Let me know if this works for you.

+5
source
 NSString *body = @"Hello Mail"; NSString *mailtoURLString = [NSString stringWithFormat:@"mailto:?body=%@", [body stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:mailtoURLString]]; 

Or, as Mihai suggested, check out the MFMailComposeViewController , which lets you send mail without leaving your application.

+5
source

The next method is to use to send mail to the user.

 -(void)sendMail:(UIImage *)image { MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; picker.mailComposeDelegate = self; // Set the subject of email [picker setSubject:@"Picture from my iPhone!"]; // Add email addresses // Notice three sections: "to" "cc" and "bcc" [picker setToRecipients:[NSArray arrayWithObjects:@TO mailID1",@TO mailID2", nil]]; [picker setCcRecipients:[NSArray arrayWithObject:@"CC MailID"]]; [picker setBccRecipients:[NSArray arrayWithObject:@"BCC Mail ID"]]; // Fill out the email body text NSString *emailBody = @"I just took this picture, check it out."; // This is not an HTML formatted email [picker setMessageBody:emailBody isHTML:NO]; // Create NSData object as PNG image data from camera image NSData *data = UIImagePNGRepresentation(image); // Attach image data to the email // 'CameraImage.png' is the file name that will be attached to the email [picker addAttachmentData:data mimeType:@"image/png" fileName:@"CameraImage"]; // Show email view [self presentModalViewController:picker animated:YES]; // Release picker [picker release]; } 
+3
source
 NSString *textToShare = @"http:yourmail.com/"; NSArray *objectsToShare = @[textToShare]; UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil]; NSArray *excludeActivities = @[UIActivityTypeAirDrop,UIActivityTypeSaveToCameraRoll]; activityVC.excludedActivityTypes = excludeActivities; [activityVC setValue:@"yourmail" forKey:@"subject"]; [self presentViewController:activityVC animated:YES completion:nil]; 
0
source

Source: https://habr.com/ru/post/895409/


All Articles