Unicode C
Unicode C
Send HTML Email with Image Downloaded from URL
Demonstrates how to compose an HTML email with an embedded image where the image data is downloaded from a URL.Chilkat Unicode C Downloads
#include <C_CkBinDataW.h>
#include <C_CkHttpW.h>
#include <C_CkMailManW.h>
#include <C_CkEmailW.h>
void ChilkatSample(void)
{
BOOL success;
HCkBinDataW bdJpg;
HCkHttpW http;
HCkMailManW mailman;
HCkEmailW email;
const wchar_t *html;
success = FALSE;
// 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);
}