iphone电子邮件附件 [英] iphone email attachment

查看:118
本文介绍了iphone电子邮件附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 MessageUI框架从我的应用程序发送带有附件的邮件。
但是我收到以下错误,

I used the MessageUI framework to send the mail with attachment from my application. But i got the following error,

2009-09-07 19:52:23.483 emailTest[11711:5b17]
 Error loading /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/System/Library/DataClassMigrators/AccountMigrator.migrator/AccountMigrator:  dlopen(/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/System/Library/DataClassMigrators/AccountMigrator.migrator/AccountMigrator, 265): Library not loaded: /System/Library/PrivateFrameworks/MobileWirelessSync.framework/MobileWirelessSync

 Referenced from: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/System/Library/DataClassMigrators/AccountMigrator.migrator/AccountMigrator

      Reason: image not found

2009-09-07 19:52:23.489 emailTest[11711:5b17] [+[AccountsManager _migrateAccountsIfNeeded]] Accounts migration failed
[Switching to process 11711 local thread 0xf03]

我的代码是

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc]init];
picker.mailComposeDelegate = self;
[picker setSubject:@"This is iPhone email   attachment test"];

UIImage *sampleImg = [UIImage imageNamed:@"iPhone.jpg"];
NSData *imageData = UIImageJPEGRepresentation(sampleImg, 1);
[picker addAttachmentData:imageData mimeType:@"image/png" fileName:@"iPhone.jpg"];


NSString *emailBody = @"I am sending the image attachment with iPhone email service";
[picker setMessageBody:emailBody isHTML:YES];

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

请帮助我。

推荐答案

您不必在文件名中输入扩展名。喜欢iphone.jpg不行。只是在文件名中写下iphone,因为你已经定义了mimeType。而且你必须定义资源的路径。

You do not have to type extension in your filename. like "iphone.jpg" is not working. just write "iphone" in filename because you already define mimeType. And also you have to define path for resource.

以下是使用邮件附加rainy.png文件的示例代码。

Below is the sample code to attach "rainy.png" file with mail.

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

[picker setSubject:@"Hello"];


// 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 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:@"rainy"];

// Fill out the email body text
NSString *emailBody = @"It is raining";
[picker setMessageBody:emailBody isHTML:NO];

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

这篇关于iphone电子邮件附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆