【发布时间】:2011-04-01 05:47:38
【问题描述】:
我想以编程方式从我的应用程序中将 .doc 文件作为电子邮件附件发送。
【问题讨论】:
-
这是一个预先存在的 .doc 文件,还是动态生成的?
-
我正在通过我的应用程序动态创建它
标签: objective-c ipad mfmailcomposeviewcontroller
我想以编程方式从我的应用程序中将 .doc 文件作为电子邮件附件发送。
【问题讨论】:
标签: objective-c ipad mfmailcomposeviewcontroller
使用 -[MFMailComposeViewController addAttachmentData:] 的 mimeType 为“application/msword”。例如:
- (void)displayComposerSheet {
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"I'm attaching a word document!"];
// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:@"first@example.com"];
NSArray *ccRecipients = [NSArray arrayWithObjects:@"second@example.com", @"third@example.com", nil];
NSArray *bccRecipients = [NSArray arrayWithObject:@"fourth@example.com"];
[picker setToRecipients:toRecipients];
[picker setCcRecipients:ccRecipients];
[picker setBccRecipients:bccRecipients];
// Attach a doc to the email
NSString *path = [[NSBundle mainBundle] pathForResource:@"MyDocument" ofType:@"doc"];
NSData *myData = [NSData dataWithContentsOfFile:path];
[picker addAttachmentData:myData mimeType:@"application/msword" fileName:@"MyDocument"];
// Fill out the email body text
NSString *emailBody = @"Please see the attached document.";
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
[picker release];
}
【讨论】: