HTML图像未显示在通过VBA中的Gmail API发送的MIME邮件中,已使用3D

时间:2015-06-11 23:22:03

标签: html excel-vba mime gmail-api vba

我在VBA中通过Gmail REST API发送HTML电子邮件,并且HTML图像未显示在已发送的邮件中。我添加了一个img标题标签,我已尝试将已批准的“ci3.googleusercontent.com”版本的图片作为源代码,尝试了png& JPG。由于我在POST请求的正文中发送电子邮件信息,我认为我不需要使用Base64。没有任何空格,所以不必担心%20并转换为+。

还有其他想法吗?

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

以下是收到电子邮件HTML源代码的摘录。我的“已发送”文件夹中发送的电子邮件也没有显示图像,但HTML也存在,这也很奇怪......

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

1 个答案:

答案 0 :(得分:0)

我找到了一个解决方案,但希望有人可以解释发生了什么。我在从Gmail REST发送的电子邮件中显示HTML图片时出现问题。但是,我发现如果我把&#34; 3D&#34;在图像源前面,即<img src=3D'http://www.example.com/logo.png'>,图像将显示在电子邮件中。一些搜索显示3D与引用指针有关,但我不明白。 3D的目的是什么?使用它有危险吗?

找到这个old SO thread,其中解释了: