HTML image not showing up in MIME message sent via Gmail API in VBA, Used 3D

733 Views Asked by At

I'm sending HTML emails via Gmail REST API in VBA and the HTML image is not showing up in the sent message. I've added an img title tag, I've tried an approved "ci3.googleusercontent.com" version of the image as the source, tried png & jpg. Since I'm sending the email information in the POST request's body I don't think I need to use Base64. There aren't any spaces so shouldn't have to worry about %20 and converting to +.

Any other ideas?

Sub SendGmail()
    Dim result As String, myURL As String, postData As String
    Dim winHttpReq As Object
    Dim x As Integer

    Set winHttpReq = CreateObject("WinHttp.WinHttpRequest.5.1")

    myURL = "https://www.googleapis.com/upload/gmail/v1/users/me/messages/send"
    postData = "From: 'Michael F' <[email protected]>" & vbCr & _
            "Subject: Test Message " & Now() & vbCr & _
            "Reply-To: [email protected]" & vbCr & _
            "To: [email protected]" & vbCr & _
            "Content-Type: text/html; charset=utf-8" & vbCr & _
            "Content-Transfer-Encoding: quoted-printable" & vbCr & vbCr & _
            "<b>Test Message</b><p>" & vbCr & vbCr & _
            "<img alt='ExampleLogo' " & _
            "title='ExampleLogo' src='http://www.example.com/LogoSignature.png'>"

            '*Putting 3D right after src= solved the problem!*

    winHttpReq.Open "POST", myURL, False
        winHttpReq.SetRequestHeader "Host", "www.googleapis.com"
        winHttpReq.SetRequestHeader "Content-Length", Len(postData)
        winHttpReq.SetRequestHeader "Content-Type", "message/rfc822"
        winHttpReq.SetRequestHeader "Authorization", "Bearer <mycode>"
        winHttpReq.Send (postData)
        Set winHttpReq = Nothing   
End Sub

Here is an excerpt of the received email HTML source. The sent email in my Sent folder doesn't show the image either, but the HTML is there which is also strange...

MIME-Version: 1.0
X-Received: by 10.50.30.9 with SMTP id o9mr838664igh.36.1434063589114; Thu, 11
 Jun 2015 15:59:49 -0700 (PDT)
Received: from 4.apps.googleusercontent.com named unknown by
 gmailapi.google.com with HTTPREST; Thu, 11 Jun 2015 18:59:48 -0400
From: "'Michael F'" <[email protected]>
Reply-To: [email protected]
Date: Thu, 11 Jun 2015 18:59:48 -0400
Message-ID: <[email protected]>
Subject: Test Message 6/11/2015 17:59:51
To: [email protected]
Content-Type: multipart/alternative; boundary=047d7bd76aead100b6051845f2ef

--047d7
Content-Type: text/plain; charset=UTF-8

*Test Message*

--047d7
Content-Type: text/html; charset=UTF-8

<b>Test Message</b><p>

<img></p>

--047d7--
1

There are 1 best solutions below

0
On

I found a solution but hoping someone can explain what is going on. I was having issues with an HTML image showing up in emails I sent from Gmail REST. However, I found if I put "3D" in front of the image source ie <img src=3D'http://www.example.com/logo.png'> the image will show up in the email. Some searching shows the 3D has something to do with quote pointable but I don't understand that. What is the purpose of the 3D? Is there any danger using it?

Found this old SO thread which explains: