How to add a image in email body using MFMailComposeViewController(如何使用 MFMailComposeViewController 在电子邮件正文中添加图像)
问题描述
我正在尝试找出在电子邮件正文中添加图像而不是在 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 在电子邮件正文中添加图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 MFMailComposeViewController 在电子邮件正文中
基础教程推荐
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01