PowerBuilder Requires Chilkat v11.0.0+
PowerBuilder
SendGrid: Send two private appointment reminders in one request
See more SendGrid Examples
Create an active reminder template with subject Appointment reminder and body Hello {{first_name}}, your appointment is {{appointment_time}}. Use your template ID, verified sender and two test addresses. Each recipient has a separate personalization; placing both addresses in a single To array would expose them to one another and share the same template data.
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("template_id","d-YOUR_ACTIVE_TEMPLATE_ID")
// Each recipient gets a separate envelope and a private appointment time.
loo_Message.UpdateString("personalizations[0].to[0].email","avery@example.com")
loo_Message.UpdateString("personalizations[0].dynamic_template_data.first_name","Avery")
loo_Message.UpdateString("personalizations[0].dynamic_template_data.appointment_time","Tuesday at 9:30 AM Central")
loo_Message.UpdateString("personalizations[1].to[0].email","robin@example.com")
loo_Message.UpdateString("personalizations[1].dynamic_template_data.first_name","Robin")
loo_Message.UpdateString("personalizations[1].dynamic_template_data.appointment_time","Wednesday at 2:00 PM Central")
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