2011-04-29 184 views

回答

0

下面是我們如何發送附件與我們的郵件(以下附加一個JPEG和假設filename,其設置其他地方到你的包中的一個位置,但是真正的任何NSData對象都可以工作,但是隻要你正確設置你的mimeType就可以啓動它)

MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init]; 
mailViewController.mailComposeDelegate = self; 
[mailViewController setMessageBody:@"Some Message" isHTML:YES]; 
[mailViewController setSubject:@"My Subject"]; 
[mailViewController addAttachmentData:[NSData dataWithContentsOfFile:fileName] mimeType:@"image/jpeg" fileName:@"PrettyPicture.jpg"]; 
[self presentModalViewController:mailViewController animated:YES]; 
[mailViewController release]; 
2

下面是將郵件附加到文件的示例代碼。

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; 
picker.mailComposeDelegate = self; 

[picker setSubject:@"Hello"]; 


// Set up recipients 
NSArray *toRecipients = [NSArray arrayWithObject:@"[email protected]"]; 
NSArray *ccRecipients = [NSArray arrayWithObjects:@"[email protected]", @"[email protected]", nil]; 
NSArray *bccRecipients = [NSArray arrayWithObject:@"[email protected]"]; 

[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:@"myFile"]; 

// Fill out the email body text 
NSString *emailBody = @"Message body : my first email sending "; 
[picker setMessageBody:emailBody isHTML:NO]; 

[self presentModalViewController:picker animated:YES]; 
[picker release];