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
(PureBasic) Send HTML Email with Image Downloaded from URLDemonstrates how to compose an HTML email with an embedded image where the image data is downloaded from a URL.
IncludeFile "CkBinData.pb" IncludeFile "CkHttp.pb" IncludeFile "CkEmail.pb" IncludeFile "CkMailMan.pb" Procedure ChilkatExample() ; This example requires the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. ; First download the image we'll be adding to the HTML "img" tag. bdJpg.i = CkBinData::ckCreate() If bdJpg.i = 0 Debug "Failed to create object." ProcedureReturn EndIf http.i = CkHttp::ckCreate() If http.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success.i = CkHttp::ckQuickGetBd(http,"https://www.chilkatsoft.com/images/starfish.jpg",bdJpg) If success = 0 Debug CkHttp::ckLastErrorText(http) CkBinData::ckDispose(bdJpg) CkHttp::ckDispose(http) ProcedureReturn EndIf mailman.i = CkMailMan::ckCreate() If mailman.i = 0 Debug "Failed to create object." ProcedureReturn EndIf ; Use your SMTP server.. CkMailMan::setCkSmtpHost(mailman, "smtp.yourserver.com") CkMailMan::setCkSmtpPort(mailman, 587) CkMailMan::setCkStartTLS(mailman, 1) ; Set the SMTP login/password CkMailMan::setCkSmtpUsername(mailman, "my_login") CkMailMan::setCkSmtpPassword(mailman, "my_password") ; Create an HTML email. email.i = CkEmail::ckCreate() If email.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkEmail::setCkSubject(email, "HTML Email with Image") CkEmail::setCkFrom(email, "Dave <somebody@mydomain.com>") CkEmail::ckAddTo(email,"Chilkat","info@chilkatsoft.com") html.s = "<html><body><p>This is an HTML email with an embedded image.</p><p><img src=" + Chr(34) + "starfish.jpg" + Chr(34) + " /></p></body></html>" CkEmail::ckSetHtmlBody(email,html) ; Note: The "starfish.jpg" here must match the name in the "img" tag's "src" attribute in the HTML above. success = CkEmail::ckAddRelatedBd2(email,bdJpg,"starfish.jpg") If success = 0 Debug CkEmail::ckLastErrorText(email) CkBinData::ckDispose(bdJpg) CkHttp::ckDispose(http) CkMailMan::ckDispose(mailman) CkEmail::ckDispose(email) ProcedureReturn EndIf CkEmail::ckSaveEml(email,"qa_output/out.eml") ; success = mailman.SendEmail(email); ; if (success == ckfalse) { ; println mailman.LastErrorText; ; return; ; } ; ; ignore = mailman.CloseSmtpConnection(); Debug "Success." CkBinData::ckDispose(bdJpg) CkHttp::ckDispose(http) CkMailMan::ckDispose(mailman) CkEmail::ckDispose(email) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.