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

DataFlex 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

 

 

 

(DataFlex) Forward an Email using CreateForward

Reads an email from an IMAP server, creates a forward version of the email using the CreateForward method, and sends the email to another recipient.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-win32.pkg

Procedure Test
    Handle hoImap
    Boolean iSuccess
    Integer iNumEmails
    Variant vEmail
    Handle hoEmail
    Variant vEForward
    Handle hoEForward
    Handle hoSbHtmlBody
    Handle hoSbPtBody
    Handle hoMailman
    String sTemp1
    Boolean bTemp1

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    // Read the 1st (most recent) email in an Inbox.
    Get Create (RefClass(cComChilkatImap)) To hoImap
    If (Not(IsComObjectCreated(hoImap))) Begin
        Send CreateComObject of hoImap
    End

    // Connect to an IMAP server.
    Set ComSsl Of hoImap To True
    Set ComPort Of hoImap To 993
    Get ComConnect Of hoImap "imap.someMailServer.com" To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoImap To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Login
    Get ComLogin Of hoImap "myLogin" "myPassword" To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoImap To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Select an IMAP mailbox
    Get ComSelectMailbox Of hoImap "Inbox" To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoImap To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComNumMessages Of hoImap To iNumEmails

    // Fetch the email at the last sequence number.
    // (We are assuming the Inbox has at least 1 email)
    Get ComFetchSingle Of hoImap iNumEmails False To vEmail
    If (IsComObject(vEmail)) Begin
        Get Create (RefClass(cComChilkatEmail)) To hoEmail
        Set pvComObject Of hoEmail To vEmail
    End
    Get ComLastMethodSuccess Of hoImap To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoImap To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Disconnect from the IMAP server.
    Get ComDisconnect Of hoImap To iSuccess

    Get ComSubject Of hoEmail To sTemp1
    Showln sTemp1

    Get ComCreateForward Of hoEmail To vEForward
    If (IsComObject(vEForward)) Begin
        Get Create (RefClass(cComChilkatEmail)) To hoEForward
        Set pvComObject Of hoEForward To vEForward
    End

    // The eForward email has no To or CC recipients yet.
    // Add one or more..
    Get ComAddTo Of hoEForward "Chilkat Support" "support@chilkatsoft.com" To iSuccess

    // We also need to specify the From name/address.
    Set ComFromAddress Of hoEForward To "matt@someMailServer.com"
    Set ComFromName Of hoEForward To "Matt"

    // If we wish to add text at the start of the email body:
    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbHtmlBody
    If (Not(IsComObjectCreated(hoSbHtmlBody))) Begin
        Send CreateComObject of hoSbHtmlBody
    End
    Get ComHasHtmlBody Of hoEForward To bTemp1
    If (bTemp1 = True) Begin
        Get ComGetHtmlBody Of hoEForward To sTemp1
        Get ComAppend Of hoSbHtmlBody sTemp1 To iSuccess
        Get ComPrepend Of hoSbHtmlBody "<p>Hello, this is an email I'm forwarding to you...</p>" To iSuccess
        Get ComGetAsString Of hoSbHtmlBody To sTemp1
        Send ComSetHtmlBody To hoEForward sTemp1
    End

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbPtBody
    If (Not(IsComObjectCreated(hoSbPtBody))) Begin
        Send CreateComObject of hoSbPtBody
    End
    Get ComHasPlainTextBody Of hoEForward To bTemp1
    If (bTemp1 = True) Begin
        Get ComGetPlainTextBody Of hoEForward To sTemp1
        Get ComAppend Of hoSbPtBody sTemp1 To iSuccess
        Get ComPrepend Of hoSbPtBody "Hello, this is an email I'm forwarding to you..." + (character(13)) + (character(10)) + (character(13)) + (character(10)) To iSuccess
        Get ComGetAsString Of hoSbPtBody To sTemp1
        Send ComSetTextBody To hoEForward sTemp1 "text/plain"
    End

    // We could save the .eml, then double-click on it to view in our mail program, such as Outlook or Thunderbird..
    Get ComSaveEml Of hoEForward "qa_output/forward.eml" To iSuccess

    // We could send (forward) the email..
    Get Create (RefClass(cComChilkatMailMan)) To hoMailman
    If (Not(IsComObjectCreated(hoMailman))) Begin
        Send CreateComObject of hoMailman
    End

    Set ComSmtpHost Of hoMailman To "smtp.someMailServer.com"
    Set ComSmtpUsername Of hoMailman To "myLogin"
    Set ComSmtpPassword Of hoMailman To "myPassword"
    Set ComSmtpPort Of hoMailman To 587
    Set ComStartTLS Of hoMailman To True

    Get ComSendEmail Of hoMailman vEForward To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoMailman To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComCloseSmtpConnection Of hoMailman To iSuccess
    If (iSuccess <> True) Begin
        Showln "Connection to SMTP server not closed cleanly."
    End

    Showln "Mail Sent!"

    Send Destroy of hoEForward
    Send Destroy of hoEmail


End_Procedure

 

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