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 在电子邮件正文中
- Android viewpager检测滑动超出范围 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01