Classic ASP Requires Chilkat v11.0.0+
Classic ASP
Send email to blind-copy recipients with Gmail
See more GMail REST API Examples
Live send. Replace all sample addresses. Gmail takes its recipients from the submitted MIME To, Cc, and Bcc headers. Use AddBcc on a new Email and keep the Bcc header when serializing it for Gmail. Treat the submission as private because it contains the blind-copy addresses.
Authorize the application with https://www.googleapis.com/auth/gmail.send. 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 email = Server.CreateObject("Chilkat.Email")
' Use the authorized mailbox or one of its configured send-as addresses.
email.From = "Sender <sender@example.com>"
success = email.AddTo("Recipient","recipient@example.net")
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( email.LastErrorText) & "</pre>"
Response.End
End If
email.Subject = "Sample message"
email.Charset = "utf-8"
email.Body = "Hello from the Gmail API."
' Gmail needs the blind recipient in the submitted MIME; use the normal Chilkat 11.x Bcc behavior.
success = email.AddBcc("Blind recipient","blind@example.org")
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( email.LastErrorText) & "</pre>"
Response.End
End If
set mime = Server.CreateObject("Chilkat.BinData")
success = email.GetMimeBd(mime)
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( email.LastErrorText) & "</pre>"
Response.End
End If
ERROR: ASP example cannot use request or response as a variable name.
success = request.UpdateBd("raw","base64url",mime)
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( request.LastErrorText) & "</pre>"
Response.End
End If
success = http.HttpJson("POST","https://gmail.googleapis.com/gmail/v1/users/me/messages/send",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( "Gmail message ID: " & reply.StringOf("id")) & "</pre>"
%>
</body>
</html>