Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //************************---------------------------Mail Code Start------------------************************************************//
- -(IBAction)showPicker:(id)Sender
- {
- Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
- if (mailClass != nil)
- {
- // We must always check whether the current device is configured for sending emails
- if ([mailClass canSendMail])
- {
- [self displayComposerSheet];
- }
- else
- {
- [self launchMailAppOnDevice];
- }
- }
- else
- {
- [self launchMailAppOnDevice];
- }
- }
- //---------------------------------------------------------------------------/////
- -(void)displayComposerSheet
- {
- MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
- picker.mailComposeDelegate = self;
- [picker setSubject:am.mailtitle];
- // Set up recipients
- NSArray *toRecipients = [NSArray arrayWithObject:@"abc@gmail.com"];
- NSArray *ccRecipients = [NSArray arrayWithObjects:@"abc@yahoo.com", nil];
- NSArray *bccRecipients = [NSArray arrayWithObject:@"abc@gmail.com"];
- [picker setToRecipients:toRecipients];
- [picker setCcRecipients:ccRecipients];
- [picker setBccRecipients:bccRecipients];
- NSString *emailBody = am.mailtext;
- [picker setMessageBody:emailBody isHTML:YES];
- [self presentModalViewController:picker animated:YES];
- [picker release];
- }
- //---------------------------------------------------------------------------/////
- -(void)pushAlertCancel
- {
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Status:" message:@"Canceled!!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
- [alert show];
- [alert release];
- }
- -(void)pushAlertSent
- {
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Status:" message:@"Mail Sent!!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
- [alert show];
- [alert release];
- }
- -(void)pushAlertSaved
- {
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Status:" message:@"Mail Saved To Drafts!!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
- [alert show];
- [alert release];
- }
- -(void)pushAlertNotSent
- {
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Status:" message:@"Mail Not Sent!!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
- [alert show];
- [alert release];
- }
- -(void)pushAlertFailed
- {
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Status:" message:@"Mail Failed!!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
- [alert show];
- [alert release];
- }
- //---------------------------------------------------------------------------/////
- - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
- {
- // message.hidden = NO;
- message.text=@"hello";
- // Notifies users about errors associated with the interface
- switch (result)
- {
- case MFMailComposeResultCancelled:
- [self pushAlertCancel]; //message.text = @"Result: canceled";
- break;
- case MFMailComposeResultSaved:
- //message.text = @"Result: saved";
- [self pushAlertSaved];
- break;
- case MFMailComposeResultSent:
- // message.text = @"Result: sent";
- [self pushAlertSent];
- break;
- case MFMailComposeResultFailed:
- // message.text = @"Result: failed";
- [self pushAlertFailed];
- break;
- default:
- // message.text = @"Result: not sent";
- [self pushAlertNotSent];
- break;
- }
- [self dismissModalViewControllerAnimated:YES];
- }
- //---------------------------------------------------------------------------/////
- -(void)launchMailAppOnDevice
- {
- NSString *recipients = @"mailto:first@example.com?cc=second@example.com,third@example.com&subject=Hello from California!";
- NSString *body = @"&body=It is raining in sunny California!";
- NSString *email = [NSString stringWithFormat:@"%@%@", recipients, body];
- email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];
- }
- //---------------------------------------------------------------------------/////
- //**********************---------------------Mail Code Finish------------------****************************//
Add Comment
Please, Sign In to add comment