使用我的以下脚本时,图片和日志文件将成为附件。当我用Outlook打开它时,电子邮件中的其他一些文本(默认签名)将作为index.htm附加到电子邮件中。
使用iOS 7.0.6从iPad发送电子邮件
在Mac上的Mail-Application中,文件位于文本的中间,然后才会写入邮件应用程序的签名。
当我只附加图像时,一切都会好的。当我附加logfile.txt时,它就像我描述的那样,并且在Mac的Mail-Application中,所有特殊键(德语如ä,ü)都不会被解码为utf8。
我在哪里弄错了?
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
currentIOS = [[UIDevice currentDevice] systemVersion];
vNumber = @"V"VersionNumber;
subject = [NSString stringWithFormat:@"%@ - Meine aktuelle iPad-Nummer",vNumber];
message = [NSString stringWithFormat:@"<p>Hallo liebes EDV-Team,</p> <p>mein Betriebssystem ist: %@</p><p>Und meine iPad-Nummer lautet: %@</p>", currentIOS, udid];
[controller setToRecipients: [NSArray arrayWithObjects:@"email@webpage.de", nil]];
[controller setSubject:subject];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *txtFilePath = [documentsDirectory stringByAppendingPathComponent:@"logfile.txt"];
NSData *noteData = [NSData dataWithContentsOfFile:txtFilePath];
[controller addAttachmentData:noteData mimeType:@"text/plain" fileName:@"logfile.txt"];
UIImage *roboPic = [UIImage imageNamed:@"world_smilie.png"];
NSData *imageData = UIImagePNGRepresentation(roboPic);
[controller addAttachmentData:imageData mimeType:@"image/png" fileName:@"smile.png"];
[controller setMessageBody:message isHTML:YES];
if ([self respondsToSelector:@selector(presentViewController:animated:completion:)]){
[self presentViewController:controller animated:YES completion:nil];
}
我更改了文本文件的代码:
I change the code like elio.d told me:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *txtFilePath = [documentsDirectory stringByAppendingPathComponent:@"logfile.txt"];
NSString *txtFileContent = [NSString stringWithContentsOfFile:txtFilePath encoding:NSUTF8StringEncoding error:nil];
NSData *txtFileData = [txtFileContent dataUsingEncoding:NSUTF8StringEncoding];
[controller addAttachmentData:txtFileData
mimeType:@"text/plain"
fileName:@"logfile.txt"];
将附加logfile.txt,但是来自ipad的签名将附加到ATT00002.htm中的电子邮件中,现在我还得到一个空的ATT00001.htm
当我更改电子邮件的类型时,我遇到同样的问题(isHTML:NO)