2011-04-08 55 views
0

我想不同的用戶保存的電子郵件地址,我想打開郵箱的新郵件時,我點擊了郵件,一樣的iPhone電話簿電子郵件,iPhone中的郵箱編程?

我應該怎麼辦???

回答

1

您應該使用MFMailComposeViewController類,並實行MFMailComposeViewControllerDelegate協議,

首先發送一個消息:

MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init]; 
controller.mailComposeDelegate = self; 
[controller setSubject:@"My Subject"]; 
[controller setMessageBody:@"Hello there." isHTML:NO]; 
[self presentModalViewController:controller animated:YES]; 
[controller release]; 

一旦你發送你將得到代表回撥mailComposeController

- (void)mailComposeController:(MFMailComposeViewController*)controller 
      didFinishWithResult:(MFMailComposeResult)result 
         error:(NSError*)error; 
{ 
    if (result == MFMailComposeResultSent) { 
    NSLog(@"It's gone!"); 
    } 
    [self dismissModalViewControllerAnimated:YES]; 
} 
1

郵件中創建新的消息:

NSString *subject = @"The subject"; 
NSString *body = @"The message"; 
NSString *address = @"[email protected]"; 
NSString *cc = @"[email protected]"; 
NSString *path = [NSString stringWithFormat:@"mailto:%@?cc=%@&subject=%@&body=%@", address, cc, subject, body]; 
NSURL *url = [NSURL URLWithString:[path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 
[[UIApplication sharedApplication] openURL:url];