1.
// HomeViewController.h
// MailDemo
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
@interface HomeViewController : UIViewController<MFMailComposeViewControllerDelegate>
- (IBAction)displayComposerSheet;
// MailDemo
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
@interface HomeViewController : UIViewController<MFMailComposeViewControllerDelegate>
- (IBAction)displayComposerSheet;
@end
2.
//
// HomeViewController.m
// MailDemo
//
#import "HomeViewController.h"
@interface HomeViewController ()
@end
@implementation HomeViewController
- (IBAction)displayComposerSheet
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"你好"];
NSArray *toRecipients = [NSArray arrayWithObjects:@"111@qq.com", nil];
NSArray *ccRecipients = [NSArray arrayWithObjects:@"222@qq.com", @"333@qq.com", nil];
NSArray *bccRecipients = [NSArray arrayWithObjects:@"444@qq.com", nil];
[picker setToRecipients:toRecipients];
[picker setCcRecipients:ccRecipients];
[picker setBccRecipients:bccRecipients];
NSString *path = [[NSBundle mainBundle] pathForResource:@"mm" ofType:@"jpg"];
NSData *myData = [NSData dataWithContentsOfFile:path];
[picker addAttachmentData:myData mimeType:@"image/jpg" fileName:@"mm"];
NSString *emailBody = @"很漂亮的MM";
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
[picker release];
}
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
[self dismissModalViewControllerAnimated:YES];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
// HomeViewController.m
// MailDemo
//
#import "HomeViewController.h"
@interface HomeViewController ()
@end
@implementation HomeViewController
- (IBAction)displayComposerSheet
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"你好"];
NSArray *toRecipients = [NSArray arrayWithObjects:@"111@qq.com", nil];
NSArray *ccRecipients = [NSArray arrayWithObjects:@"222@qq.com", @"333@qq.com", nil];
NSArray *bccRecipients = [NSArray arrayWithObjects:@"444@qq.com", nil];
[picker setToRecipients:toRecipients];
[picker setCcRecipients:ccRecipients];
[picker setBccRecipients:bccRecipients];
NSString *path = [[NSBundle mainBundle] pathForResource:@"mm" ofType:@"jpg"];
NSData *myData = [NSData dataWithContentsOfFile:path];
[picker addAttachmentData:myData mimeType:@"image/jpg" fileName:@"mm"];
NSString *emailBody = @"很漂亮的MM";
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
[picker release];
}
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
[self dismissModalViewControllerAnimated:YES];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
致力于ios开发