PowerBuilder Requires Chilkat v11.0.0+
PowerBuilder
SendGrid: Send product updates with a topic unsubscribe link
See more SendGrid Examples
Use the numeric ID of your existing Product updates unsubscribe group and a verified sender. The ASM tag expands to the recipient-specific link for this group. A click opts the recipient out of this topic; a global unsubscribe applies across topics.
Chilkat PowerBuilder Downloads
integer li_rc
long li_Success
oleobject loo_Http
oleobject loo_Resp
oleobject loo_Message
li_Success = 0
// Assumes Chilkat is unlocked. See Global Unlock Sample.
li_Success = 0
loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
destroy loo_Http
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Http.RequireSslCertVerify = 1
// Supply your API key from protected configuration; AuthToken adds the Bearer prefix.
loo_Http.AuthToken = "SENDGRID_API_KEY"
loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")
loo_Message = create oleobject
li_rc = loo_Message.ConnectToNewObject("Chilkat.JsonObject")
loo_Message.UpdateString("from.email","sender@example.com")
loo_Message.UpdateString("personalizations[0].to[0].email","recipient@example.com")
loo_Message.UpdateInt("asm.group_id",12345)
loo_Message.UpdateString("subject","Product updates: November edition")
loo_Message.UpdateString("content[0].type","text/html")
loo_Message.UpdateString("content[0].value","<p>The new catalog is available.</p><p><a href=~"<%asm_group_unsubscribe_raw_url%>~">Unsubscribe from product updates</a></p>")
li_Success = loo_Http.HttpJson("POST","https://api.sendgrid.com/v3/mail/send",loo_Message,"application/json",loo_Resp)
if li_Success <> 1 then
if loo_Resp.StatusCode = 0 then
Write-Debug loo_Http.LastErrorText
else
Write-Debug "HTTP " + string(loo_Resp.StatusCode) + ": " + loo_Resp.BodyStr
end if
destroy loo_Http
destroy loo_Resp
destroy loo_Message
return
end if
if loo_Resp.StatusCode <> 202 then
Write-Debug "HTTP " + string(loo_Resp.StatusCode) + ": " + loo_Resp.BodyStr
destroy loo_Http
destroy loo_Resp
destroy loo_Message
return
end if
Write-Debug "Accepted for delivery (HTTP 202)."
destroy loo_Http
destroy loo_Resp
destroy loo_Message