Classic ASP Requires Chilkat v11.0.0+
Classic ASP
Constant Contact V3: Create a newsletter draft from an HTML file
See more Constant Contact Examples
Save your newsletter as UTF-8 in newsletter.html. Put the tracking tag inside the body, for example <body><h1>Workshop news</h1>[[trackingImage]]</body>. Supply a unique campaign name and confirmed sender and reply-to addresses for your account. Constant Contact uses the account’s physical mailing address in the footer by default.
This creates a custom-code draft. The example writes the campaign and primary activity IDs to newsletter-selection.json for the test and scheduling examples. If the response is lost after creation, look up the campaign by name before creating another draft.
Authorize the application using the same account and credential store.
Constant Contact developer guide
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 vault = Server.CreateObject("Chilkat.Secrets")
vault.Location = "local_manager"
vault.AutoSplit = 1
set entry = Server.CreateObject("Chilkat.JsonObject")
success = entry.UpdateString("appName","ConstantContactV3")
success = entry.UpdateString("service","OAuth2")
success = entry.UpdateString("username","my-account")
set tokens = Server.CreateObject("Chilkat.JsonObject")
loaded = vault.GetSecretJson(entry,tokens)
If (loaded <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Run the desktop authorization example using this account and store.") & "</pre>"
Response.End
End If
If (tokens.JsonTypeOf("access_token") <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "The saved authorization has no access token.") & "</pre>"
Response.End
End If
set http = Server.CreateObject("Chilkat.Http")
http.RequireSslCertVerify = 1
http.AuthToken = tokens.StringOf("access_token")
set resp = Server.CreateObject("Chilkat.HttpResponse")
set html = Server.CreateObject("Chilkat.StringBuilder")
success = html.LoadFile("newsletter.html","utf-8")
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not read newsletter.html.") & "</pre>"
Response.End
End If
If (html.Contains("[[trackingImage]]",1) <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Add [[trackingImage]] inside the HTML body.") & "</pre>"
Response.End
End If
set draft = Server.CreateObject("Chilkat.JsonObject")
success = draft.UpdateString("name","Workshop newsletter")
success = draft.UpdateInt("email_campaign_activities[0].format_type",5)
success = draft.UpdateString("email_campaign_activities[0].from_name","Workshop team")
success = draft.UpdateString("email_campaign_activities[0].from_email","news@example.com")
success = draft.UpdateString("email_campaign_activities[0].reply_to_email","workshops@example.com")
success = draft.UpdateString("email_campaign_activities[0].subject","Upcoming workshops")
success = draft.UpdateString("email_campaign_activities[0].html_content",html.GetAsString())
success = http.HttpJson("POST","https://api.cc.email/v3/emails",draft,"application/json",resp)
If ((success <> 1) And (resp.StatusCode <= 0)) Then
Response.Write "<pre>" & Server.HTMLEncode( "Create draft: HTTP request failed.") & "</pre>"
Response.End
End If
If ((success <> 1) Or (resp.StatusCode <> 201)) Then
Response.Write "<pre>" & Server.HTMLEncode( "Create draft: HTTP " & resp.StatusCode & " " & resp.BodyStr) & "</pre>"
Response.End
End If
set campaign = Server.CreateObject("Chilkat.JsonObject")
success = campaign.Load(resp.BodyStr)
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Expected a JSON object in the response.") & "</pre>"
Response.End
End If
' The campaign identifies the newsletter. The primary activity identifies the email to test or schedule.
set primary = Server.CreateObject("Chilkat.JsonObject")
success = campaign.FindRecord2("campaign_activities","role","primary_email",1,primary)
If ((success <> 1) Or (primary.JsonTypeOf("campaign_activity_id") <> 1)) Then
Response.Write "<pre>" & Server.HTMLEncode( "No primary email activity ID in the response.") & "</pre>"
Response.End
End If
selectedCampaign = campaign.StringOf("campaign_id")
selectedActivity = primary.StringOf("campaign_activity_id")
If ((selectedCampaign = "") Or (selectedActivity = "")) Then
Response.Write "<pre>" & Server.HTMLEncode( "Missing campaign or activity ID.") & "</pre>"
Response.End
End If
Response.Write "<pre>" & Server.HTMLEncode( "Campaign ID: " & selectedCampaign) & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( "Primary activity ID: " & selectedActivity) & "</pre>"
set selection = Server.CreateObject("Chilkat.JsonObject")
success = selection.UpdateString("name",campaign.StringOf("name"))
success = selection.UpdateString("campaign_id",selectedCampaign)
success = selection.UpdateString("campaign_activity_id",selectedActivity)
success = selection.WriteFile("newsletter-selection.json")
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not save newsletter-selection.json. Keep the IDs printed above.") & "</pre>"
Response.End
End If
Response.Write "<pre>" & Server.HTMLEncode( "Saved newsletter-selection.json.") & "</pre>"
%>
</body>
</html>