iOS Swift使用电子邮件正文发送图像(不附件)

时间:2015-08-26 07:27:36

标签: ios swift

使用SWIFT我需要在电子邮件正文中发送一些图像,其中包含一些其他文本内容。 只是尝试以下方式,我可以发送电子邮件...

在iPhone发送的项目中已正确发送,但在gmail中它没有正确呈现。图像标签以纯文本形式打印...

    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)
    }

在这里真的无法解决我出错的问题......

0 个答案:

没有答案