Inline image attachment in MFMailcomposer is not showing in recipients mail client

I am creating a mail app in swift. In this case, I need to send image attachments with the description text below for each image. I am creating this by setting the mailbody to be html as I need the lines between the images which I am not using the addAttachmentData method. I could see the Mailcontroller view with images and strings as expected. But the images are not displayed in the recipient's mail. Kind, help me with this.

Below is my code,

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"])

      

+3


source to share





All Articles