Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PowerBuilder) Create GMail DraftDemonstrates how to create a new GMail draft email.
integer li_rc integer li_Success oleobject loo_Email oleobject loo_SbMime oleobject loo_Json oleobject loo_Http string ls_Url oleobject loo_Resp // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. // Use the Chilkat Email API to create or load an email. loo_Email = create oleobject // Use "Chilkat_9_5_0.Email" for versions of Chilkat < 10.0.0 li_rc = loo_Email.ConnectToNewObject("Chilkat.Email") if li_rc < 0 then destroy loo_Email MessageBox("Error","Connecting to COM object failed") return end if loo_Email.Subject = "This is a test GMail email created using Chilkat." loo_Email.Charset = "utf-8" loo_Email.AddPlainTextAlternativeBody("This is a test") loo_Email.AddHtmlAlternativeBody("<html><body><p>This is a <b>test</b></body></html>") // We'll need to get the full MIME of the email encoded to a base64url string. loo_SbMime = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbMime.ConnectToNewObject("Chilkat.StringBuilder") loo_Email.GetMimeSb(loo_SbMime) loo_SbMime.Encode("base64url","utf-8") // The body of the HTTP request will be JSON.. loo_Json = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject") loo_Json.UpdateSb("message.raw",loo_SbMime) // Upload the email to GMail as a draft. loo_Http = create oleobject // Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0 li_rc = loo_Http.ConnectToNewObject("Chilkat.Http") loo_Http.AuthToken = "GMAIL-ACCESS-TOKEN" ls_Url = "https://www.googleapis.com/gmail/v1/users/me/drafts" loo_Resp = loo_Http.PostJson3(ls_Url,"application/json",loo_Json) if loo_Http.LastMethodSuccess <> 1 then Write-Debug loo_Http.LastErrorText destroy loo_Email destroy loo_SbMime destroy loo_Json destroy loo_Http return end if // A status code of 200 indicates success. Write-Debug "Response status code: " + string(loo_Resp.StatusCode) Write-Debug "Response body:" Write-Debug loo_Resp.BodyStr destroy loo_Resp // The response body contains JSON. // Use the online tool at Generate JSON Parsing Code // to generate JSON parsing code. // A sample successful JSON response: // { // "id": "r-2607584557788895307", // "message": { // "id": "166f09932c662e93", // "threadId": "166f09932c662e93", // "labelIds": [ // "DRAFT" // ] // } // } destroy loo_Email destroy loo_SbMime destroy loo_Json destroy loo_Http |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.