我使用 MFMailComposeViewController 在 iPhone 上创建电子邮件。这些邮件包括文本、文本附件和一些图像附件。
if ([MFMailComposeViewController canSendMail]) {
mailController = [[MFMailComposeViewController alloc] init];
[mailController setToRecipients:recipients];
if ([ccRecipients count] > 0) [mailController setCcRecipients:ccRecipients];
[mailController setSubject:project];
[mailController setMessageBody:message isHTML:NO];
if (csv) {
[mailController addAttachmentData:csvData mimeType:@"text/csv" fileName:csvFileName];
}
QEMailAddPicturesOperation * operation = [[QEMailAddPicturesOperation alloc] init];
operation.delegate = self;
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[queue addOperation:operation];
}
@implementation QEMailAddPicturesOperation
- (void) main {
....
for (NSString * fileName in listOfPictures) {
NSString * path = [directory stringByAppendingPathComponent:fileName];
NSData * imageData = UIImageJPEGRepresentation([UIImage imageWithContentsOfFile:path], PIC_COMPRESSION_RATE );
[mailController addAttachmentData:imageData mimeType:@"image/jpg" fileName:fileName];
}
}
一切正常,我可以发送邮件。但结果是:
Content-Type: multipart/mixed; boundary=Apple-Mail-256A861D-10BB-4031-8DFB-0E8FDA8F9337
....
Content-Transfer-Encoding: 7bit
Mime-Version: 1.0 (1.0)
X-Mailer: iPhone Mail (9A405)
....
--Apple-Mail-256A861D-10BB-4031-8DFB-0E8FDA8F9337
Content-Transfer-Encoding: 7BIT
Content-Type: TEXT/plain;
charset=us-ascii
--Apple-Mail-256A861D-10BB-4031-8DFB-0E8FDA8F9337
Content-Disposition: inline;
filename=MFA_001.JPG
Content-Type: IMAGE/jpg;
....
您会看到:邮件编写器在附加的(和 base64 编码的)图像之间放置了几行文本。
Outlook 2010 将这些行解释为附件 (ATT......)。例如,发送 8 张图像会在 Outlook 中创建 8 个额外但为空的附件。Outlook 还将 iPhone-Mail 的签名显示为附件。Mac 上的 Outlook 2011 可以正常工作。
如何避免在 iPhone 上创建空行或在 Outlook(2007、2010)中创建附件?