1

我正在嘗試發送附帶圖像附件和HTML的電子郵件。問題是,當HTML打開時,圖像顯示爲內聯而不是附件(我使用gmail)。MFMailComposer - 用HTML連接圖像ON

如果我設置了isHTML:NO,那麼該圖像會正常顯示爲可下載的附件。我如何將圖像作爲附件發送給html消息?

NSData *imageAttachment = UIImageJPEGRepresentation(myUIImage,1); 

MFMailComposeViewController *mailView = [[MFMailComposeViewController alloc] init]; 
[mailView setSubject:@"My Email Subject!"]; 
[mailView addAttachmentData:imageAttachment mimeType:@"image/jpeg" fileName:@"imageAttachment.jpg"]; 
[mailView setMessageBody:messageBody isHTML:YES]; 

Thanks〜!!

+1

我我已經使用了這個接口,並且知道無法控制這種行爲。 (但附件應該仍然可以在任何體面的郵件閱讀器下載。) –

+0

嗨pws5068,你有沒有想過解決這個問題呢? – platypus

回答

0

您附加圖像的方法是正確的,並且您得到的結果也達到標準。

無論哪種方式,最終用戶(無論他們使用Gmail或不),應該得到附件。

例如,Windows Live Mail應將其視爲附件,在Mac OS中使用Mail時,您會看到圖像內聯。

0

您必須添加圖像作爲附件。您使用HTML看到的呈現電子郵件無法通過丟失的圖片網址正確呈現。

這裏有一個例子:需要注意的是,如果你想包括像PDF文檔,你必須包含一個圖像,否則mfmailcomposer會失敗......這在蘋果的bug。

我找到了解決辦法... Isubmitted蘋果雷達關於它的錯誤。 MFMailcomposer有,你必須爲了得到怪異的物品,如一個PDF工作...試試這個和你的卡更換PDF文件使用你的額外附件一起發送的圖像錯誤:

MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init]; 
NSString *emailSubject = [NSString localizedStringWithFormat:@"MedicalProfile"]; 
[controller setSubject:emailSubject]; 


NSString *fileName = [NSString stringWithFormat:@"%@.pdf", profileName]; 
NSString *saveDirectory = NSTemporaryDirectory(); 
NSString *saveFileName = fileName; 
NSString *documentPath = [saveDirectory stringByAppendingPathComponent:saveFileName]; 

*** YOU MUST INCLUDE AN IMAGE OR THE PDF ATTATCHMENT WILL FAIL!!!*** 
// Attach a PDF file to the email 
NSData *pdfData = [NSData dataWithContentsOfFile:documentPath];  
[controller addAttachmentData:pdfData mimeType:@"application/pdf" fileName:fileName]; 


// Attach an image to the email 
NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"miniDoc" ofType:@"png"]; 
NSData *imageData = [NSData dataWithContentsOfFile:imagePath]; 
[controller addAttachmentData:imageData mimeType:@"image/png" fileName:@"doctor"]; 


[controller setMessageBody:[NSString stringWithFormat:@"%@'s Medical Profile attatched!", profileName] isHTML:NO]; 

[self presentModalViewController:controller animated:YES]; 
controller.mailComposeDelegate = self; 
[controller release]; 
+0

謝謝,非常有幫助! – c0d3Junk13