Classic ASP Requires Chilkat v11.0.0+
Classic ASP
SendGrid: Create a newsletter draft, then schedule the reviewed draft
See more SendGrid Examples
Prepare a Marketing Campaigns design with a subject, content, and an unsubscribe module. Supply the design and list UUIDs, a verified marketing sender ID, and the unsubscribe group ID. The first run creates only a draft. After reviewing the audience and content, run the scheduling branch with that same ID. Single Sends use an ISO 8601 UTC string, unlike Mail Send’s numeric Unix timestamp.
Create a Single Send · Schedule a Single Send
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.
success = 0
set http = Server.CreateObject("Chilkat.Http")
http.RequireSslCertVerify = 1
' Supply your API key from protected configuration; AuthToken adds the Bearer prefix.
http.AuthToken = "SENDGRID_API_KEY"
set resp = Server.CreateObject("Chilkat.HttpResponse")
' Leave this empty to create a draft. To schedule, supply the ID of an already reviewed draft.
reviewedDraftId = ""
If (reviewedDraftId = "") Then
set draft = Server.CreateObject("Chilkat.JsonObject")
success = draft.UpdateString("name","November newsletter")
success = draft.UpdateString("send_to.list_ids[0]","YOUR_LIST_UUID")
success = draft.UpdateInt("email_config.sender_id",12345)
success = draft.UpdateInt("email_config.suppression_group_id",67890)
success = draft.UpdateString("email_config.design_id","YOUR_NEWSLETTER_DESIGN_UUID")
success = http.HttpJson("POST","https://api.sendgrid.com/v3/marketing/singlesends",draft,"application/json",resp)
If (success <> 1) Then
If (resp.StatusCode = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( http.LastErrorText) & "</pre>"
Else
Response.Write "<pre>" & Server.HTMLEncode( "HTTP " & resp.StatusCode & ": " & resp.BodyStr) & "</pre>"
End If
Response.End
End If
If (resp.StatusCode <> 201) Then
Response.Write "<pre>" & Server.HTMLEncode( "HTTP " & resp.StatusCode & ": " & resp.BodyStr) & "</pre>"
Response.End
End If
set created = Server.CreateObject("Chilkat.JsonObject")
success = created.Load(resp.BodyStr)
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Unexpected response: expected JSON.") & "</pre>"
Response.End
End If
draftId = created.StringOf("id")
If (created.HasMember("id") <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Missing id in response.") & "</pre>"
Response.End
End If
Response.Write "<pre>" & Server.HTMLEncode( "Draft created: " & draftId & ". Review it in Marketing Campaigns before scheduling.") & "</pre>"
Response.End
End If
' The example selects tomorrow at the current UTC time. Use your approved send time.
set releaseTime = Server.CreateObject("Chilkat.CkDateTime")
success = releaseTime.SetFromCurrentSystemTime()
success = releaseTime.AddDays(1)
set schedule = Server.CreateObject("Chilkat.JsonObject")
success = schedule.UpdateString("send_at",releaseTime.GetAsTimestamp(0))
success = http.SetUrlVar("draft",reviewedDraftId)
success = http.HttpJson("PUT","https://api.sendgrid.com/v3/marketing/singlesends/{$draft}/schedule",schedule,"application/json",resp)
If (success <> 1) Then
If (resp.StatusCode = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( http.LastErrorText) & "</pre>"
Else
Response.Write "<pre>" & Server.HTMLEncode( "HTTP " & resp.StatusCode & ": " & resp.BodyStr) & "</pre>"
End If
Response.End
End If
If (resp.StatusCode <> 201) Then
Response.Write "<pre>" & Server.HTMLEncode( "HTTP " & resp.StatusCode & ": " & resp.BodyStr) & "</pre>"
Response.End
End If
set scheduled = Server.CreateObject("Chilkat.JsonObject")
success = scheduled.Load(resp.BodyStr)
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Unexpected response: expected JSON.") & "</pre>"
Response.End
End If
Response.Write "<pre>" & Server.HTMLEncode( scheduled.StringOf("status") & ": " & scheduled.StringOf("send_at")) & "</pre>"
%>
</body>
</html>