2015-06-11 18 views
0

我通過VBA中的Gmail REST API發送HTML電子郵件,並且HTML圖像未顯示在發送的消息中。我添加了一個img標題標籤,我試過了一個經過批准的「ci3.googleusercontent.com」版本的圖片來源,試過了png & jpg。由於我在POST請求的正文中發送電子郵件信息,因此我不認爲我需要使用Base64。沒有任何空格,因此不必擔心%20並轉換爲+。HTML圖像沒有顯示在VBA中通過Gmail API發送的MIME消息中,使用3D

還有其他想法嗎?

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 

這裏是的摘錄收到電子郵件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'" <[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-- 

回答

0

我找到了一個解決方案,但希望有人能解釋一下是怎麼回事。我在從Gmail REST發送的電子郵件中顯示HTML圖像時遇到了問題。然而,我發現如果我把「3D」放在圖像源的前面,即<img src=3D'http://www.example.com/logo.png'>圖像將顯示在電子郵件中。一些搜索顯示3D與引用點對點有關,但我不明白。 3D的目的是什麼?使用它有沒有危險?

找到這個old SO thread解釋:

相關問題