問題描述
我正在嘗試找出在電子郵件正文中添加圖像而不是在 ios 中作為附件添加的最佳方法.
I am trying to find out the best way to add an image inside the body of the email and not as attachment in ios.
1) Apple 提供了一個功能addAttachment",文檔說,要在內容中添加任何圖像,我們應該使用此功能,但我嘗試了該功能,并發送了一封郵件,我檢查了我的瀏覽器,它是作為附件接收的.
1) Apple has provided a function "addAttachment" and the doc says, to add any image in the content, we should use this function, but I tried that function, and sent an mail, I checked on my browser, it is recieved as an attachment.
2) 其次,許多博客都說要使用 base64 編碼, 但那也行不通,圖像被作為損壞的圖像發送.
2) Secondly, many blogs say to use base64 encoding, but that also wont work, image is sent as a broken one.
所以朋友們,請幫助我找到最好的解決方案.
So friends, please help me out to find the best available solution to do this.
問候蘭吉特
推薦答案
設置郵件格式為 HTML.此代碼在我的應用程序中運行良好.
Set email format as HTML. This code is woking fine in my app.
MFMailComposeViewController *emailDialog = [[MFMailComposeViewController alloc] init];
NSString *htmlMsg = @"<html><body><p>This is your message</p></body></html>";
NSData *jpegData = UIImageJPEGRepresentation(emailImage, 1.0);
NSString *fileName = @"test";
fileName = [fileName stringByAppendingPathExtension:@"jpeg"];
[emailDialog addAttachmentData:jpegData mimeType:@"image/jpeg" fileName:fileName];
emailDialog setSubject:@"email subject"];
[emailDialog setMessageBody:htmlMsg isHTML:YES];
[self presentModalViewController:emailDialog animated:YES];
[emailDialog release];
斯威夫特 5
import MessageUI
func composeMail() {
let mailComposeVC = MFMailComposeViewController()
mailComposeVC.addAttachmentData(UIImage(named: "emailImage")!.jpegData(compressionQuality: CGFloat(1.0))!, mimeType: "image/jpeg", fileName: "test.jpeg")
mailComposeVC.setSubject("Email Subject")
mailComposeVC.setMessageBody("<html><body><p>This is your message</p></body></html>", isHTML: true)
self.present(mailComposeVC, animated: true, completion: nil)
}
這篇關于如何使用 MFMailComposeViewController 在電子郵件正文中添加圖像的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!