0

Using SWIFT I need to send an image in the email body with some other text content on it. just tried in following way and I can send the email...

In iPhone sent items it have properly sent, but in gmail it doesn't render properly. The image tag is printed as plain text...

    if MFMailComposeViewController.canSendMail()
    {
        let mailComposerVC = MFMailComposeViewController()
        mailComposerVC.mailComposeDelegate = self

        mailComposerVC.setToRecipients(["myemail@gmail.com"])
        mailComposerVC.setSubject("Sample Title")

        var body: String = "<html><body><h1>My Image as below</h1> <br/>"

        if let imageData = UIImagePNGRepresentation(myImageView.image) // Get the image from ImageView and convert to NSData
        {
            var base64String: String = imageData.base64EncodedStringWithOptions(NSDataBase64EncodingOptions.allZeros)
            body = body + "<div><img src='data:image/png;base64,\(base64String)' height='100' width='150'/></div>"
        }
        body = body + "</body></html>"
        mailComposerVC.setMessageBody(body, isHTML: true)

        self.presentViewController(mailComposerVC, animated: true, completion: nil)
    }

Can't really get the point where I am going wrong in here...

JibW
  • 4,538
  • 17
  • 66
  • 101
  • I think most mail clients disable or disallow the src='data:...' way. – hola Aug 26 '15 at 08:16
  • Relevant stackoverflow: http://stackoverflow.com/a/4312865/3287366 – hola Aug 26 '15 at 08:18
  • Hi Thanks for the response... But there it reference to a url. In here it is impossible as the image is stored in the phone and that need to be used... – JibW Aug 26 '15 at 09:29

0 Answers0