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
(DataFlex) Forward an Email using CreateForwardReads an email from an IMAP server, creates a forward version of the email using the CreateForward method, and sends the email to another recipient.
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.