2

我使用MFMailComposeViewController在iPhone上創建eMails。這些郵件包括文本,文本附件和一些圖像附件。MFMailComposeViewController在圖像附件前生成空行

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郵件的簽名顯示爲附件。 Mac上的Outlook 2011工作。

如何避免在iPhone上創建空行或在Outlook(2007,2010)中創建附件?

回答

0

我已經轉發了這裏的問題 - MFMailComposeViewController Attaches Signature as .txt file因爲沒有答案。

經過一番更多的挖掘,這是交換服務器的問題,而不是Swift/iOS /等。它與Exchange預期電子郵件內容的排序方式有關。如果新版本的Exchange解決了這個問題,我還沒有找到明確的答案。麻省理工學院的鏈接特別提到了Exchange Server 2007 & 2010.另外,我能夠確認問題出在郵件由Exchange發送,而沒有收到。

http://kb.mit.edu/confluence/pages/viewpage.action?pageId=4981187

https://support.microsoft.com/en-us/help/969854/the-body-of-a-message-is-shown-incorrectly-as-an-attachment-if-you-try