iOS Question Email Server image problem


Licensed User
Hi Gurus / Experts / Jedi Masters :)

I am trying to send a picture embedded in my email as pure html.
I set my email message to html (Mail.HtmlBody = True), then just create a string with my image html as base64.
My code used to work 100% with the old email server I was using, but I have now changed to a different mail server.

The problem with the new Email server it seems, is that the Server is removing every " it finds along with the character right behind the " (if there is no space behind the ").

So for example my image html which I prepare looks like this:
<DIV ><img alt="Picture" hspace=src="data:image/png;base64, R0lGODlhngGFAPcAAB4bHCEd..............etc.......etc........

But when I look at the source of the email in my inbox, it now looks like this:
<DIV ><img alt=icture" hspace=src=ata:image/png;base64, R0lGODlhngGFAPcAAB4bHCEd..............etc.......etc........

So as you can see it has removed the 'P' of 'Picture' along with the " in front the the P, as well as the 'd' of 'data' again along with the " in front of it.
It has not however, removed the " at the end of "Picture" (since there is a space behind it).
So now obviously my image will no longer work! :(

I am guessing I have to do some kind of character escaping / encoding to fix this in B4i, but not sure how to do this?
Please can someone help?

Thank you for your time,



Licensed User
Hi Erel, thanks for the reply, always appreciated!

I have actually managed to get it to work, simply by adding more " to my string like this:

    Dim S As StringUtils
    Dim Bytes() As Byte =  File.ReadBytes(strPath,strImageName)  'Read the image into an array of bytes.
    Dim strImageBase64 As String
    strImageBase64 = S.EncodeBase64(Bytes)   'Now Convert our Image to Base64 string so that it can be directly embedded into the HTML.
    'Prepare the image HTML 'src' property which will contain the Image data as Base64.
    'NB!!!!! This is where I had to add 6 quotes on either side to get it to work!
    Dim strImageSource As String = """""" & "data:image/png;base64, " & strImageBase64 & """"""    '    "data:image/png;base64, abc123//444553....etc...."
    'Finally Concatenate it together to form the final HTML string.
    Dim strHTML As String = ""    
    strHTML = "<img src=""" & strImageSource & """/>"

Hope this can help someone else stuck with this!
Upvote 0