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) Send HTML Email with Embedded Image Loaded from MemoryDemonstrates how to compose an HTML email with an embedded image where the image data is loaded directly from memory.
Use ChilkatAx-win32.pkg Procedure Test Handle hoFac Variant hoImageBytes Handle hoMailman Variant vEmail Handle hoEmail Boolean iSuccess String sContentIdStarfish Handle hoSbHtml Integer iNumReplacements Boolean iSuccess String sTemp1 Boolean bTemp1 // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. // First load image data into memory. // This example loads image data from a file. // However, your application could get the image data from any other source, such as // from a database. Get Create (RefClass(cComCkFileAccess)) To hoFac If (Not(IsComObjectCreated(hoFac))) Begin Send CreateComObject of hoFac End Get ComReadEntireFile Of hoFac "qa_data/jpg/starfish.jpg" To hoImageBytes // The mailman object is used for sending and receiving email. Get Create (RefClass(cComChilkatMailMan)) To hoMailman If (Not(IsComObjectCreated(hoMailman))) Begin Send CreateComObject of hoMailman End // Use your SMTP server hostname. This example uses office365, but it could be any SMTP server.. Set ComSmtpHost Of hoMailman To "outlook.office365.com" Set ComSmtpPort Of hoMailman To 587 Set ComStartTLS Of hoMailman To True // Set the SMTP login/password Set ComSmtpUsername Of hoMailman To "OFFICE365-SMTP-LOGIN" Set ComSmtpPassword Of hoMailman To "OFFICE365-SMTP-PASSWORD" // Create a new email object Get Create (RefClass(cComChilkatEmail)) To hoEmail If (Not(IsComObjectCreated(hoEmail))) Begin Send CreateComObject of hoEmail End Set ComSubject Of hoEmail To "HTML Email with Image Loaded from In-Memory Bytes" Set ComFrom Of hoEmail To "Chilkat Support <my-office365-user@mydomain.com>" Get ComAddTo Of hoEmail "Chilkat Support" "support@chilkatsoft.com" To iSuccess Get ComAddRelatedData Of hoEmail "starfish.jpg" vImageBytes To sContentIdStarfish Get ComLastMethodSuccess Of hoEmail To bTemp1 If (bTemp1 <> True) Begin Get ComLastErrorText Of hoEmail To sTemp1 Showln sTemp1 Procedure_Return End // The src attribute for the image tag is set to the contentIdStarfish: Get Create (RefClass(cComChilkatStringBuilder)) To hoSbHtml If (Not(IsComObjectCreated(hoSbHtml))) Begin Send CreateComObject of hoSbHtml End Get ComAppend Of hoSbHtml "<html><body><p>This is an HTML email with an embedded image.</p>" To iSuccess Get ComAppend Of hoSbHtml '<p><img src="cid:CONTENT_ID_STARFISH" /></p></body></html>' To iSuccess Get ComReplace Of hoSbHtml "CONTENT_ID_STARFISH" sContentIdStarfish To iNumReplacements Get ComGetAsString Of hoSbHtml To sTemp1 Send ComSetHtmlBody To hoEmail sTemp1 Get pvComObject of hoEmail to vEmail Get ComSendEmail Of hoMailman vEmail To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoMailman To sTemp1 Showln sTemp1 End Else Begin Showln "Mail Sent!" End End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.