From within my iPad application I would like to invoke iPad's E-mail app with custom body text. Senders and subject will be empty, the only parameter I would like to set is the text of the e-mail message. How could I do that?
Thanks!
The iOS software development kit (iOS SDK) is a collection of tools for the creation of apps for Apple's mobile operating system.
Why not just open an email message composer inside your app?
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];
Take a look at MFMailComposeViewController
in Apple's documentation. You can use it like this:
MFMailComposeViewController *controller=[[MFMailComposeViewController alloc]init];
controller.delegate = self;
[controller setMessageBody:<#yourBody#> isHTML:<#isHTML#>];
[self presentModalViewController:controller animated:YES];
[controller release];
Don't forget to add #import <MessageUI/MessageUI.h>
in your .h
file. It will call methods in your delegate to let you know when it was canceled or the email was sent (successfully or not). Let me know if that works for you.
NSString *body = @"Hello Mail";
NSString *mailtoURLString = [NSString stringWithFormat:@"mailto:?body=%@", [body stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:mailtoURLString]];
Or, as Mihai suggested, take a look at MFMailComposeViewController
which allows you to send mail without leaving your app.
Following method is use for sending mail to 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];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With