Examples
♦ All examples are fired on an A5W page.
♦ THESE ARE EXAMPLES, OBVIOUSLY YOU WILL NEED TO CHANGE THE EMAIL ADDRESSES, ATTACHMENTS, ETC.
Simple example
ms.send_to = "steve@sqst.com"
ms.from_email = "steve@iadn.com"
ms.from_name = "Steve Wood, AlphaToGo"
ms.subject = "SparkPost Test"
ms.message_html = "<b>Test HTML Message</b>"
ms.message_text = "Hardly ever used plain text message"
dim pResult as p = wt_email_send_sparkpost("",ms)
DataSource Example
ms.send_to = "none" '==SET TO ANY NON-NULL VALUE
ms.from_email = "steve@iadn.com"
ms.from_name = "Steve Wood, AlphaToGo"
ms.subject = "SparkPost Test"
ms.message_html = "<b>Test HTML Message</b>"
ms.message_text = "Hardly ever used plain text message"
'==DATASOURCE. EXAMPLE
dim ms.dataSource as c = <<%txt%
[
{ email:"steve@sqst.com", Fname: "Steve", Lname: "Smith" },
{ email:"steve1@sqst.com", Fname: "Steve1", Lname: "Smith1" },
]
%txt%
dim pResult as p = wt_email_send_sparkpost("",ms)
Full Example with Attachments, Global and Email-Specific Merge Variables
dim ms as p
ms.send_to = "steve1@sqst.com"
ms.send_to_cc = ""
ms.send_to_bcc = ""
ms.from_email = "steve@iadn.com"
ms.from_name = "Steve Wood, AlphaToGo"
ms.subject = "SparkPost Test by ^|FNameGlobal|^" ' Example of global merge fields
ms.message_html = "<b>Test HTML Message</b> for *|Fname|* *|Lname|*" ' Example email-specific merge fields
ms.message_text = "Hardly ever used plain text message"
'==ATTACHMENTS SIMPLE METHOD
'==Note - 'file exists' error checking is built in to the function for this attachments list
dim ms.attachments as c = ""
ms.attachments = "c:\a5\scratch.pdf,c:\a5\aero1.csv"
'==ATTACHMENTS ARRAY. EXAMPLES
'==Note - you will need to add your own error checking to ensure file exists for the attachmentsArray
dim ms.attachmentsArray[1] as p
ms.attachmentsArray[1].type = resolve_mime_type("pdf")
ms.attachmentsArray[1].name = "scratch.pdf"
ms.attachmentsArray[1].content= base64encode(file.to_blob("c:\a5\scratch.pdf"))
'==GLOBAL MERGE VARIABLES. EXAMPLES
dim ms.global_merge_vars[1] as p
ms.global_merge_vars[1].name = "FnameGlobal"
ms.global_merge_vars[1].content = "Global Steve Wood"
'==INDIVIDUAL MERGE VARIABLES. EXAMPLES
dim ms.merge_vars[2] as p
dim ms.merge_vars[1].vars[1] as p ' one email, one item
ms.merge_vars[1].recp = "steve1@sqst.com"
ms.merge_vars[1].vars[1].name = "Fname"
ms.merge_vars[1].vars[1].content = "Steve (email-specific merge)"
dim ms.merge_vars[2].vars[2] as p ' one email, two items
ms.merge_vars[2].recp = "steve2@sqst.com"
ms.merge_vars[2].vars[1].name = "Fname"
ms.merge_vars[2].vars[1].content = "Ralph (email-specific merge)"
ms.merge_vars[2].vars[2].name = "Lname"
ms.merge_vars[2].vars[2].content = "Wood (email-specific merge)"
dim pResult as p = wt_email_send_sparkpost("",ms)
'==SUGGESTED DEBUGGING. UNCOMMENT TO TEST IN A5W PAGE OR SEND TO A FILE TO REVIEW
?"ERROR : " + pResult.error_text + "<hr>" '==ERRORS FOM THE ALPHA FUNCTION, NOT FROM SPARKPOST
?"RETURNED: " + pResult.body + "<hr>" '==RETURNED FROM SPARKPOST IN JSON
?"POSTED : " + pResult.json + "<hr>" '==WHAT WE POSTED TO SPARKPOST
?"APIERROR: " + convert_type(pResult.error,"C") + "<hr>" '==True IF SPARKPOST RETURNED AN ERROR OF ANY KIND
?"VERSION : " + pResult.version + "<hr>" '==VERSION OF THE ALPHA FUNCTION