Sample code for 30+ languages & platforms
Classic ASP Requires Chilkat v11.0.0+

Mark a Gmail message as read or archive it

See more GMail REST API Examples

Choose read or archive and supply a Gmail message ID. Marking a message as read removes UNREAD. Archiving removes INBOX while keeping the message available elsewhere in the mailbox. Each run performs the selected action on one message. Removing a label that is already absent is safe to repeat.

Authorize the application with https://www.googleapis.com/auth/gmail.modify. The example reads the access token from gmail-token.json in a private working directory. Authorize a desktop application.

Google documentation

Chilkat Classic ASP Downloads

Classic ASP
<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")
action = "read"
ERROR: ASP example cannot use request or response as a variable name.
If (action = "read") Then
    success = request.UpdateString("removeLabelIds[0]","UNREAD")
    If (success <> 1) Then
        Response.Write "<pre>" & Server.HTMLEncode( request.LastErrorText) & "</pre>"
        Response.End
    End If

Else
    If (action <> "archive") Then
        Response.Write "<pre>" & Server.HTMLEncode( "Choose read or archive.") & "</pre>"
        Response.End
    End If

    success = request.UpdateString("removeLabelIds[0]","INBOX")
    If (success <> 1) Then
        Response.Write "<pre>" & Server.HTMLEncode( request.LastErrorText) & "</pre>"
        Response.End
    End If

End If

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("/modify")
success = http.HttpJson("POST",url.GetAsString(),request,"application/json",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("id") <> 1) Or (reply.StringOfEquals("id","",1) = 1)) Then
    Response.Write "<pre>" & Server.HTMLEncode( "Expected id in the response.") & "</pre>"
    Response.End
End If

Response.Write "<pre>" & Server.HTMLEncode( "Completed " & action & " for message " & reply.StringOf("id")) & "</pre>"

%>
</body>
</html>