调用IOS邮件系统发送邮件

1.导入MessageUI.framework框架

2.在需要应用的控制器头文件:#import <MessageUI/MessageUI.h>,并加入委托:<MFMailComposeViewControllerDelegate>

3.实现方法:

-(void)displayComposerSheet 
{
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;
    
    [picker setSubject:@"Enter Your Subject!"];
    
    // Set up recipients
    NSArray *toRecipients = [NSArray arrayWithObject:@"donald.wong5@gmail.com"]; 
     
    
    [picker setToRecipients:toRecipients];
    
    // Attach an image to the email
    NSString *path = [[NSBundle mainBundle] pathForResource:@"" ofType:@"png"];
    NSData *myData = [NSData dataWithContentsOfFile:path];
    [picker addAttachmentData:myData mimeType:@"image/png" fileName:@""];
    
    // Fill out the email body text
         
    [self presentModalViewController:picker animated:YES];
    
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{    
     
    [self dismissModalViewControllerAnimated:YES];
}

posted @ 2012-09-19 14:49  hellocby  阅读(4467)  评论(0编辑  收藏  举报