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 by Attaching the Existing Email to a New EmailDemonstrates how to forward an email by attaching the email to a new email. This example uses the AttachEmail method, which is new in Chilkat v9.5.0.87. This example reads an email from an IMAP server, attaches the email to a new email, and sends the new email.
Use ChilkatAx-win32.pkg Procedure Test Handle hoImap Boolean iSuccess Integer iNumEmails Variant vEmail Handle hoEmail Variant vEForward Handle hoEForward 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 // Create a new email. The email we just read will be attached to this email. Get Create (RefClass(cComChilkatEmail)) To hoEForward If (Not(IsComObjectCreated(hoEForward))) Begin Send CreateComObject of hoEForward End Get ComAddTo Of hoEForward "Chilkat Support" "support@chilkatsoft.com" To iSuccess Set ComFromAddress Of hoEForward To "matt@someMailServer.com" Set ComFromName Of hoEForward To "Matt" Set ComSubject Of hoEForward To "This is an email with another email attached." Send ComSetHtmlBody To hoEForward "<p>Hello, this is an email I'm forwarding to you. See the attached email.</p>" // Attach the email. Get ComAttachEmail Of hoEForward vEmail To iSuccess // 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 pvComObject of hoEForward to vEForward 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 hoEmail End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.