我正在swift中创建一个邮件App。在这里,我需要为每个图像发送下面的描述文本的图像附件。我通过将mailbody设置为html来创建它,因为我需要使用addAttachmentData方法在图像之间使用字符串。我可以按预期看到带有图像和字符串的Mailcontroller视图。但图像不会显示在接收邮件中。恩迪帮助我。
以下是我的代码,
var mail:MFMailComposeViewController = MFMailComposeViewController()
mail.mailComposeDelegate = self
mail.setSubject("Subject")
var image = self.images[0] as UIImage
let imgData:NSData = UIImagePNGRepresentation(image);
var imageString = imgData.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(rawValue: 0))
var emailBody = "<html><body> Start of mail body <p><img src='data:image/png;base64,\(imageString)' width='\(image.size.width)' height='\(image.size.height)'> End of mailbody </p></body></html>"
mail.setMessageBody(emailBody, isHTML:true)
mail.setToRecipients(["sampleMail@gmail.com"])