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' <mf@example.com>" & vbCr & _
"Subject: Test Message " & Now() & vbCr & _
"Reply-To: support@example.com" & vbCr & _
"To: JoeTest@gmail.com" & 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'" <mf@example.com>
Reply-To: support@example.com
Date: Thu, 11 Jun 2015 18:59:48 -0400
Message-ID: <CAKUypCw@mail.gmail.com>
Subject: Test Message 6/11/2015 17:59:51
To: JoeTest@gmail.com
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--