I know this question has been asked before, but I haven't seen anything recent so am hoping for a fix. Currently I am sending an email with an html body that contains two image tags. Originally I was just doing something like
<img width="100" src="http://cdn1-www.dogtime.com/assets/uploads/gallery/30-impossibly-cute-puppies/impossibly-cute-puppy-2.jpg" >
but now am just trying to use a local image and use base64 encoding, so something like
<img width="100" src="data:image/png;base64,...>
So far I've had success with that from within iOSs mail but once I open it in Gmail or Outlook or anything else it isn't working.
Has any one found a solution to this?
My code...
let mailComposer = MFMailComposeViewController()
mailComposer.mailComposeDelegate = self
mailComposer.setToRecipients([String]())
mailComposer.setSubject("email with image in body")
mailComposer.setMessageBody(getHtmlBody(), isHTML: true)
self.presentViewController(mailComposer, animated : true, completion: nil)
getHtmlBody(){
let imgData:NSData = UIImagePNGRepresentation(UIImage(named : "logo")!)
let dataString = imgData.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(rawValue: 0))
var html = "<!DOCTYPE html>"
html = html + "<html>"
html = html + "<body>"
html = html + "<h1>Hello World, look at this image <img width=\"100\" src=\"data:image/png;base64,\(dataString)\"></h1>"
html = html + "</body>"
html = html + "</html>"
return html
}