Classic ASP Requires Chilkat v11.0.0+
Classic ASP
Inspect the MIME parts of a Gmail message
See more GMail REST API Examples
Supply a Gmail message ID and request format=full. Walk the root payload and every nested parts array, including a single-part root. For each part, show its MIME type, filename, and size. A body.attachmentId can be passed to the attachment download example. Inline body.data is already included as base64url.
Authorize the application with https://www.googleapis.com/auth/gmail.readonly. The example reads the access token from gmail-token.json in a private working directory. Authorize a desktop application.
Chilkat Classic ASP Downloads
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0
' Assumes Chilkat is unlocked. See Global Unlock Sample.
set token = Server.CreateObject("Chilkat.JsonObject")
success = token.LoadFile("gmail-token.json")
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not read gmail-token.json from the private working directory.") & "</pre>"
Response.End
End If
If ((token.JsonTypeOf("access_token") <> 1) Or (token.StringOfEquals("access_token","",1) = 1)) Then
Response.Write "<pre>" & Server.HTMLEncode( "An OAuth access token is required.") & "</pre>"
Response.End
End If
set http = Server.CreateObject("Chilkat.Http")
http.RequireSslCertVerify = 1
http.AuthToken = token.StringOf("access_token")
set resp = Server.CreateObject("Chilkat.HttpResponse")
set reply = Server.CreateObject("Chilkat.JsonObject")
set url = Server.CreateObject("Chilkat.StringBuilder")
success = url.Append("https://gmail.googleapis.com/gmail/v1/users/me/messages/")
success = url.Append("GMAIL_MESSAGE_ID")
success = url.Append("?format=full")
success = http.HttpNoBody("GET",url.GetAsString(),resp)
If (resp.StatusCode = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( "Gmail did not return an HTTP response.") & "</pre>"
Response.End
End If
If ((success <> 1) Or (resp.StatusCode < 200) Or (resp.StatusCode >= 300)) Then
Response.Write "<pre>" & Server.HTMLEncode( "Gmail HTTP " & resp.StatusCode) & "</pre>"
success = reply.Load(resp.BodyStr)
If (success = 1) Then
Response.Write "<pre>" & Server.HTMLEncode( reply.StringOf("error.message")) & "</pre>"
End If
Response.End
End If
success = reply.Load(resp.BodyStr)
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Expected a Gmail JSON response.") & "</pre>"
Response.End
End If
If (reply.JsonTypeOf("payload") <> 3) Then
Response.Write "<pre>" & Server.HTMLEncode( "Expected a MIME payload.") & "</pre>"
Response.End
End If
' Queue paths into the original JSON document so any MIME nesting depth is supported.
set paths = Server.CreateObject("Chilkat.StringTable")
success = paths.Append("payload")
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not queue the root part.") & "</pre>"
Response.End
End If
set part = Server.CreateObject("Chilkat.JsonObject")
set childPath = Server.CreateObject("Chilkat.StringBuilder")
p = 0
Do While (p < paths.Count)
success = reply.ObjectOf2(paths.StringAt(p),part)
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not read a MIME part.") & "</pre>"
Response.End
End If
Response.Write "<pre>" & Server.HTMLEncode( "Part: " & part.StringOf("mimeType") & " bytes: " & part.IntOf("body.size")) & "</pre>"
If (part.JsonTypeOf("filename") = 1) Then
If (part.StringOfEquals("filename","",1) <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Filename: " & part.StringOf("filename")) & "</pre>"
End If
End If
If (part.JsonTypeOf("body.attachmentId") = 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Attachment ID: " & part.StringOf("body.attachmentId")) & "</pre>"
Else
If (part.JsonTypeOf("body.data") = 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Body data is available in this part.") & "</pre>"
End If
End If
j = 0
Do While (j < part.SizeOfArray("parts"))
success = childPath.SetString(paths.StringAt(p))
success = childPath.Append(".parts[")
success = childPath.AppendInt(j)
success = childPath.Append("]")
success = paths.Append(childPath.GetAsString())
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not queue a child part.") & "</pre>"
Response.End
End If
j = j + 1
Loop
p = p + 1
Loop
%>
</body>
</html>