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
(Unicode C) 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.
#include <C_CkBinDataW.h> #include <C_CkHttpW.h> #include <C_CkMailManW.h> #include <C_CkEmailW.h> void ChilkatSample(void) { HCkBinDataW bdJpg; HCkHttpW http; BOOL success; HCkMailManW mailman; HCkEmailW email; const wchar_t *html; // 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 = CkBinDataW_Create(); http = CkHttpW_Create(); success = CkHttpW_QuickGetBd(http,L"https://www.chilkatsoft.com/images/starfish.jpg",bdJpg); if (success == FALSE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkBinDataW_Dispose(bdJpg); CkHttpW_Dispose(http); return; } mailman = CkMailManW_Create(); // Use your SMTP server.. CkMailManW_putSmtpHost(mailman,L"smtp.yourserver.com"); CkMailManW_putSmtpPort(mailman,587); CkMailManW_putStartTLS(mailman,TRUE); // Set the SMTP login/password CkMailManW_putSmtpUsername(mailman,L"my_login"); CkMailManW_putSmtpPassword(mailman,L"my_password"); // Create an HTML email. email = CkEmailW_Create(); CkEmailW_putSubject(email,L"HTML Email with Image"); CkEmailW_putFrom(email,L"Dave <somebody@mydomain.com>"); CkEmailW_AddTo(email,L"Chilkat",L"info@chilkatsoft.com"); html = L"<html><body><p>This is an HTML email with an embedded image.</p><p><img src=\"starfish.jpg\" /></p></body></html>"; CkEmailW_SetHtmlBody(email,html); // Note: The "starfish.jpg" here must match the name in the "img" tag's "src" attribute in the HTML above. success = CkEmailW_AddRelatedBd2(email,bdJpg,L"starfish.jpg"); if (success == FALSE) { wprintf(L"%s\n",CkEmailW_lastErrorText(email)); CkBinDataW_Dispose(bdJpg); CkHttpW_Dispose(http); CkMailManW_Dispose(mailman); CkEmailW_Dispose(email); return; } CkEmailW_SaveEml(email,L"qa_output/out.eml"); // success = mailman.SendEmail(email); // if (success == ckfalse) { // println mailman.LastErrorText; // return; // } // // ignore = mailman.CloseSmtpConnection(); wprintf(L"Success.\n"); CkBinDataW_Dispose(bdJpg); CkHttpW_Dispose(http); CkMailManW_Dispose(mailman); CkEmailW_Dispose(email); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.