Visual FoxPro Requires Chilkat v11.0.0+
Visual FoxPro
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 Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loHttp
LOCAL loResp
LOCAL loMessage
lnSuccess = 0
* Assumes Chilkat is unlocked. See Global Unlock Sample.
lnSuccess = 0
loHttp = CreateObject('Chilkat.Http')
loHttp.RequireSslCertVerify = 1
* Supply your API key from protected configuration; AuthToken adds the Bearer prefix.
loHttp.AuthToken = "SENDGRID_API_KEY"
loResp = CreateObject('Chilkat.HttpResponse')
loMessage = CreateObject('Chilkat.JsonObject')
loMessage.UpdateString("from.email","sender@example.com")
loMessage.UpdateString("personalizations[0].to[0].email","recipient@example.com")
loMessage.UpdateInt("asm.group_id",12345)
loMessage.UpdateString("subject","Product updates: November edition")
loMessage.UpdateString("content[0].type","text/html")
loMessage.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>')
lnSuccess = loHttp.HttpJson("POST","https://api.sendgrid.com/v3/mail/send",loMessage,"application/json",loResp)
IF (lnSuccess <> 1) THEN
IF (loResp.StatusCode = 0) THEN
? loHttp.LastErrorText
ELSE
? "HTTP " + STR(loResp.StatusCode) + ": " + loResp.BodyStr
ENDIF
RELEASE loHttp
RELEASE loResp
RELEASE loMessage
CANCEL
ENDIF
IF (loResp.StatusCode <> 202) THEN
? "HTTP " + STR(loResp.StatusCode) + ": " + loResp.BodyStr
RELEASE loHttp
RELEASE loResp
RELEASE loMessage
CANCEL
ENDIF
? "Accepted for delivery (HTTP 202)."
RELEASE loHttp
RELEASE loResp
RELEASE loMessage