Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

PowerBuilder Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
Secrets
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(PowerBuilder) Send GMail with Attachments

Demonstrates how to send an email containing attachments using the GMail REST API.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

integer li_rc
integer li_Success
oleobject loo_Email
string ls_Cid
oleobject loo_SbHtml
integer li_NumReplacements
string ls_MimeType
oleobject loo_SbMime
oleobject loo_Http
string ls_Url
integer li_SendGzipped
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

// The From name/address don't need to be specified. 
// GMail will automatically use your Gmail address if the following 2 lines are omitted.
loo_Email.FromName = "My Name"
loo_Email.FromAddress = "my_account_name@gmail.com"

loo_Email.AddTo("John Smith","somebody@somewhere.com")
// To add more recipients, make additional calls to AddTo or AddCC, one per recipient...

loo_Email.Subject = "This is a test GMail email created using Chilkat."
loo_Email.Charset = "utf-8"
loo_Email.AddPlainTextAlternativeBody("This is a test")

// Create an HTML email body with an embedded image.
ls_Cid = loo_Email.AddRelatedFile("qa_data/jpg/starfish.jpg")
loo_SbHtml = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbHtml.ConnectToNewObject("Chilkat.StringBuilder")

loo_SbHtml.Append("<html><body>This is a <b>test</b><br><img src=~"cid:STARFISH_CID~"/></body></html>")
li_NumReplacements = loo_SbHtml.Replace("STARFISH_CID",ls_Cid)

loo_Email.AddHtmlAlternativeBody(loo_SbHtml.GetAsString())

// Add some attachments..
ls_MimeType = loo_Email.AddFileAttachment("qa_data/helloWorld.pdf")
if loo_Email.LastMethodSuccess <> 1 then
    Write-Debug "Failed to add PDF attachment."
    destroy loo_Email
    destroy loo_SbHtml
    return
end if

ls_MimeType = loo_Email.AddFileAttachment("qa_data/msword/sample2.docx")
if loo_Email.LastMethodSuccess <> 1 then
    Write-Debug "Failed to add MS-Word attachment."
    destroy loo_Email
    destroy loo_SbHtml
    return
end if

// OK.. we now have an HTML email with 2 attachments..
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)

// Send the email.  (GMail has a 5MB limit on the total email size.)
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"

// Send using the simple upload request for the Gmail API
ls_Url = "https://www.googleapis.com/upload/gmail/v1/users/me/messages/send?uploadType=media"
li_SendGzipped = 1
loo_Resp = loo_Http.PTextSb("POST",ls_Url,loo_SbMime,"utf-8","message/rfc822",0,li_SendGzipped)
if loo_Http.LastMethodSuccess <> 1 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Email
    destroy loo_SbHtml
    destroy loo_SbMime
    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": "166f0d4ac39e50bf",
//  "threadId": "166f0d4ac39e50bf",
//  "labelIds": [
//   "SENT"
//  ]
// }


destroy loo_Email
destroy loo_SbHtml
destroy loo_SbMime
destroy loo_Http

 

© 2000-2024 Chilkat Software, Inc. All Rights Reserved.