Pages

Labels

Sunday, June 17, 2012

How to send mail using iphone

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{
message.hidden = NO;
// Notifies users about errors associated with the interface
//NSLog(result);
switch (result)
{
case MFMailComposeResultCancelled:
//message.text = @"Result: canceled";
message.text = @"Composed Mail was canceled";
break;
case MFMailComposeResultSaved:
//message.text = @"Result: saved";
message.text = @"Mail was saved";
break;
case MFMailComposeResultSent:
//message.text = @"Result: sent";
message.text = @"Mail sent successfully!";
break;
case MFMailComposeResultFailed:
//message.text = @"Result: failed";
message.text = @"Failed";
break;
default:
//message.text = @"Result: not sent";
message.text = @"Mail was not sent";
break;
}
[self dismissModalViewControllerAnimated:YES];
/*
MailComposerViewController *dal=[[MailComposerViewController alloc]init];
[self.navigationController pushViewController:dal animated:YES];
*/
//Appointment2 *dal=[[Appointment2 alloc]init];
NSLog(@"Call back");
//Appointment2 *dal=[[Appointment2 alloc]init];
//[self.navigationController pushViewController:dal animated:YES];

NSString *strinfo;
strinfo=message.text;//[NSString stringWithFormat:message.text];
UIAlertView *alert = [[UIAlertView alloc] init];
[alert setTitle:@"INFORMATION"];
[alert setMessage:strinfo];
[alert setDelegate:self];
[alert addButtonWithTitle:@"OK"];
[alert show];
[alert release];
[self.navigationController popViewControllerAnimated:YES];
}


this is the delegate method


Main function is


MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@""];//Test subject
// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:ApptNEWOBJ.appMailID]; 
NSArray *ccRecipients = [NSArray arrayWithObjects: nil]; 
//NSArray *bccRecipients = [NSArray arrayWithObject:@""]; ///support@therasoftonline.com
[picker setToRecipients:toRecipients];
[picker setCcRecipients:ccRecipients];
//[picker setBccRecipients:bccRecipients];
// Attach an image to the email
//NSString *path = [[NSBundle mainBundle] pathForResource:@"rainy" ofType:@"png"];
   // NSData *myData = [NSData dataWithContentsOfFile:path];
//[picker addAttachmentData:myData mimeType:@"image/png" fileName:@"rainy"];
// Fill out the email body text
NSString *emailBody = @"";//Testing Email body!
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
    [picker release];


0 comments:

Post a Comment

 
Loading