- Simple Example to Send Email
- Simple Example to Send HTML
Email
- Send Multipart/Alternative
Email
- Send Email with a File
Attachment
- Send Email with Multiple File
Attachments
- Zip Email Attachments
- Send High Priority Email
- Send Digitally Signed Email
- Send Encrypted Email
- Send Signed + Encrypted Email
- Send Email with Return Receipt
- Multiple CC Carbon Copy
Recipients
- Multiple BCC Blind Carbon Copy
Recipients
- Set a Bounce Address when
Sending Email
- Set a Reply-To Address when
Sending Email
- Send Email using iso-8859-1
Encoding
- Send Email using utf-8 Encoding
- Send a Chinese Email
- Send Korean Email
- Send Japanese Mail
- Send a Russian Email
- Send a Thai Email
- Send a Vietnamese Email
- Send a Georgian Email
- Send a Hindi Email
- Send HTML Email with Embedded
Image
- Send Email to Distribution List
using Mail Merge
- Add In-Memory Data as Email
Attachment
- Send 168-bit 3DES Encrypted
Email
- Read Mail from POP3 Leaving it
on the Server
- POP3 SSL - Read POP3 Email
Using SSL
- Set POP3 Connect and Read
Timeout Parameters
- Download POP3 Email
- Download POP3 Email Headers
- Fetch POP3 email headers with
filtering (PayPal example)
- Download Full Email after
Downloading Email Header
- Check Number of Messages on
POP3 Server
- Verify POP3 Login
- Verify POP3 TCP/IP Connection
- Delete a single email from a
POP3 server.
- Delete a multiple emails from a
POP3 server.
- Get Email Attachment Filename
and Size Information
- Save Email Attachments to Disk
- Save All Email Attachments to a
Directory
- Iterate and Display Email
Header Fields
- Save Email to .eml File
- Save Email in XML Format
- Convert Email to XML
- Unzip Email Attachments
In-Memory
- Unobfuscate SPAM Email
- Verify Email Digital Signature
- Read encrypted email from POP3
server and decrypt.
- Clone an Email Object
- Remove Attachments from an
Email
- Get Full MIME Source of an
Email
- Get Linked Domains in HTML
Email
- Read POP3 Mailbox with Progress
Monitoring
- Send Signed Email in Hebrew
- Parsing Delivery Status
Notification (DSN)
- Check if an Email is a DSN
- Create Forward with Original
Email Attached
- Send Email via SMTP / SSL on
Port 465
- Using SMTP STARTTLS to Send
Email over a Secure Channel
- Embed Image in
HTML Email
- Send a Simple
Email
Simple Example to Send Email
This is
a simple example showing how to send email in C++.
#define
_CRTDBG_MAP_ALLOC
#include
#include
#include
void
EmailExample(void)
{
// Any string passed to UnlockComponent
begins the 30-day trial.
bool unlocked =
mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock
component\n");
return;
}
mailman.put_SmtpHost("mail.earthlink.net");
// Create the email, add the body,
recipients, subject, etc.
email.put_Body("This is a test\r\nThis
is line #2");
email.AddTo("Chilkat
Support","support@chilkatsoft.com");
email.put_FromAddress("somebody@chilkatsoft.com");
email.put_Subject("This is a
test");
// Send the email
if (!mailman.SendEmail(&email))
{
mailman.SaveLastError("errors.xml");
}
}
int APIENTRY
WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR
lpCmdLine,
int nCmdShow)
{
freopen("stdout.txt","w",stdout);
EmailExample();
_CrtDumpMemoryLeaks();
return 0;
}
Simple Example to Send HTML Email
Download
Chilkat C++ Libraries for VC++ 8.0 / Win32Download Chilkat C++ Libraries for VC++ 7.0 / Win32
Download Chilkat C++ Libraries for VC++ 6.0 / Win32
This is a simple example showing how to send HTML email in C++.
#define _CRTDBG_MAP_ALLOC
#include
#include
#include
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkSettings.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkEmail.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkEmailBundle.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkMailMan.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkString.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkByteData.h"
void EmailExample(void)
{
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
mailman.put_SmtpHost("mail.earthlink.net");
// Create an HTML email
CkEmail email;
email.SetHtmlBody("This is my HTML email");
email.AddTo("Chilkat Support","support@chilkatsoft.com");
email.put_FromAddress("somebody@chilkatsoft.com");
email.put_Subject("This is a test");
// Send the email
if (!mailman.SendEmail(&email))
{
mailman.SaveLastError("errors.xml");
}
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
freopen("stdout.txt","w",stdout);
EmailExample();
CkSettings::cleanupMemory();
_CrtDumpMemoryLeaks();
return 0;
}
Send Multipart/Alternative Email
Download
Chilkat C++ Libraries for VC++ 8.0 / Win32Download Chilkat C++ Libraries for VC++ 7.0 / Win32
Download Chilkat C++ Libraries for VC++ 6.0 / Win32
This is a simple example showing how to send an email that has both HTML and plain-text body alternatives in C++.
#define _CRTDBG_MAP_ALLOC
#include
#include
#include
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkSettings.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkEmail.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkEmailBundle.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkMailMan.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkString.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkByteData.h"
void EmailExample(void)
{
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
mailman.put_SmtpHost("mail.earthlink.net");
// Create an email with both HTML and plain-text alternatives.
CkEmail email;
email.put_Body("This is the plain-text alternative body");
email.AddHtmlAlternativeBody("This is the HTML alternative body");
email.AddTo("Chilkat Support","support@chilkatsoft.com");
email.put_FromAddress("somebody@chilkatsoft.com");
email.put_Subject("This is a test");
// Send the email
if (!mailman.SendEmail(&email))
{
mailman.SaveLastError("errors.xml");
}
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
freopen("stdout.txt","w",stdout);
EmailExample();
CkSettings::cleanupMemory();
_CrtDumpMemoryLeaks();
return 0;
}
Send Email with a File Attachment
Download
Chilkat C/C++ Libraries for VC++ 9.0 / Win32Download Chilkat C/C++ Libraries for VC++ 8.0 / Win32
Download Chilkat C/C++ 64-bit Libraries for VC++ 8.0 / x64
Download Chilkat Visual Studio 2005 C/C++ Libs for Windows Mobile, Pocket PC, SmartPhone, WinCE
Download Chilkat C/C++ Libraries for VC++ 7.0 / Win32
Download Chilkat C/C++ Libraries for VC++ 6.0 / Win32
Download Chilkat C/C++ Libraries for VC++ 6.0, Win 95/98/NT4 Compatible
C++ code to send an email with a file attachment.
#define _CRTDBG_MAP_ALLOC
#include
#include
#include
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkSettings.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkEmail.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkEmailBundle.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkMailMan.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkString.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkByteData.h"
void EmailExample(void)
{
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
mailman.put_SmtpHost("mail.earthlink.net");
// Send an email with a file attachment.
CkEmail email;
email.put_Body("This is the body");
email.AddTo("Chilkat Support","support@chilkatsoft.com");
email.put_FromAddress("somebody@chilkatsoft.com");
email.put_Subject("This is a test");
// Add a file attachment.
if (!email.AddFileAttachment("dudeCPP.gif",0))
{
email.SaveLastError("errors.xml");
return;
}
// Send the email
if (!mailman.SendEmail(&email))
{
mailman.SaveLastError("errors.xml");
}
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
freopen("stdout.txt","w",stdout);
EmailExample();
CkSettings::cleanupMemory();
_CrtDumpMemoryLeaks();
return 0;
}
Send Email with Multiple File Attachments
Download
Chilkat C/C++ Libraries for VC++ 9.0 / Win32Download Chilkat C/C++ Libraries for VC++ 8.0 / Win32
Download Chilkat C/C++ 64-bit Libraries for VC++ 8.0 / x64
Download Chilkat Visual Studio 2005 C/C++ Libs for Windows Mobile, Pocket PC, SmartPhone, WinCE
Download Chilkat C/C++ Libraries for VC++ 7.0 / Win32
Download Chilkat C/C++ Libraries for VC++ 6.0 / Win32
Download Chilkat C/C++ Libraries for VC++ 6.0, Win 95/98/NT4 Compatible
C++ code to send an email with multiple file attachments.
#define _CRTDBG_MAP_ALLOC
#include
#include
#include
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkSettings.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkEmail.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkEmailBundle.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkMailMan.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkString.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkByteData.h"
void EmailExample(void)
{
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
mailman.put_SmtpHost("mail.earthlink.net");
// Send an email with 2 file attachments
CkEmail email;
email.put_Body("This is the body");
email.AddTo("Chilkat Support","support@chilkatsoft.com");
email.put_FromAddress("somebody@chilkatsoft.com");
email.put_Subject("This is a test");
// Add a file attachment.
if (!email.AddFileAttachment("dudeCPP.gif",0))
{
email.SaveLastError("errors.xml");
return;
}
// Add a another file attachment.
if (!email.AddFileAttachment("dude.gif",0))
{
email.SaveLastError("errors.xml");
return;
}
// Send the email
if (!mailman.SendEmail(&email))
{
mailman.SaveLastError("errors.xml");
}
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
freopen("stdout.txt","w",stdout);
EmailExample();
CkSettings::cleanupMemory();
_CrtDumpMemoryLeaks();
return 0;
}
Zip Email AttachmentsC++ source code to Zip compress email attachments.
#define _CRTDBG_MAP_ALLOC
#include
#include
#include
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkSettings.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkEmail.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkEmailBundle.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkMailMan.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkString.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkByteData.h"
void EmailExample(void)
{
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
mailman.put_SmtpHost("mail.earthlink.net");
// Send an email with zipped attachments
CkEmail email;
email.put_Body("This is the email body");
email.AddTo("Chilkat Support","support@chilkatsoft.com");
email.put_FromAddress("somebody@chilkatsoft.com");
email.put_Subject("This is the email subject");
// Add a file attachment.
if (!email.AddFileAttachment("dudeCPP.gif",0))
{
email.SaveLastError("errors.xml");
return;
}
// Add a another file attachment.
if (!email.AddFileAttachment("dude.gif",0))
{
email.SaveLastError("errors.xml");
return;
}
// Zip the attachments.
// The email will now contain one attachment: "a.zip", which contains
// the attachments previously added.
if (!email.ZipAttachments("a.zip"))
{
email.SaveLastError("errors.xml");
return;
}
// Send the email
if (!mailman.SendEmail(&email))
{
mailman.SaveLastError("errors.xml");
}
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
freopen("stdout.txt","w",stdout);
EmailExample();
CkSettings::cleanupMemory();
_CrtDumpMemoryLeaks();
return 0;
}
Send High Priority EmailC++ source code to send high-priority mail.
#define _CRTDBG_MAP_ALLOC
#include
#include
#include
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkSettings.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkEmail.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkEmailBundle.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkMailMan.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkString.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkByteData.h"
void EmailExample(void)
{
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
mailman.put_SmtpHost("mail.earthlink.net");
// Send a high-priority email.
CkEmail email;
//You can add the X-Priority header field and give it the value string "1".
//For example: email.AddHeaderField "X-Priority","1" This is the most common way of
// setting the priority of an email. "3" is normal, and "5" is the lowest.
// "2" and "4" are in-betweens, and frankly I've never seen anything
// but "1" or "3" used. Microsoft Outlook adds these header fields when
// setting a message to High priority:
// X-Priority: 1 (Highest)
// X-MSMail-Priority: High
// Importance: High
email.AddHeaderField("X-Priority","1");
email.put_Body("This is the email body");
email.AddTo("Chilkat Support","support@chilkatsoft.com");
email.put_FromAddress("somebody@chilkatsoft.com");
email.put_Subject("This is the email subject");
// Send the email
if (!mailman.SendEmail(&email))
{
mailman.SaveLastError("errors.xml");
}
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
freopen("stdout.txt","w",stdout);
EmailExample();
CkSettings::cleanupMemory();
_CrtDumpMemoryLeaks();
return 0;
}
Send Digitally Signed EmailC++ source code to send digitally signed mail.
#define _CRTDBG_MAP_ALLOC
#include
#include
#include
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkSettings.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkCert.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkEmail.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkEmailBundle.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkMailMan.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkString.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkByteData.h"
void EmailExample(void)
{
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
mailman.put_SmtpHost("mail.earthlink.net");
// Send a digitally signed email.
CkEmail email;
email.put_Body("This is the email body");
email.AddTo("Chilkat Support","matt@chilkatsoft.com");
email.put_Subject("This is the email subject");
// Load a certificate from a file and use it for signing.
CkCert cert;
cert.LoadFromFile("myCert.cer");
// The From address must match the email address in the certificate:
email.put_FromAddress("support@chilkatsoft.com");
// Check to make sure the certificate's email address matches.
CkString certEmailAddr;
cert.get_SubjectE(certEmailAddr);
if (!certEmailAddr.equals("support@chilkatsoft.com"))
{
printf("Certificate email address (%s) does not match sender's email address.\n",
certEmailAddr.getString());
return;
}
// Make sure we have the private key for signing.
if (!cert.HasPrivateKey())
{
printf("Need private key for signing!\n");
return;
}
// Use the certificate and indicate that the email should be signed.
email.put_SendSigned(true);
email.SetSigningCert(&cert);
// Send the email
if (!mailman.SendEmail(&email))
{
mailman.SaveLastError("errors.xml");
}
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
freopen("stdout.txt","w",stdout);
EmailExample();
CkSettings::cleanupMemory();
_CrtDumpMemoryLeaks();
return 0;
}
Send Encrypted Email
C++ source code to send public-key encrypted mail using a digital certificate.
#define _CRTDBG_MAP_ALLOC
#include
#include
#include
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkSettings.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkCert.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkEmail.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkEmailBundle.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkMailMan.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkString.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkByteData.h"
void EmailExample(void)
{
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
mailman.put_SmtpHost("mail.earthlink.net");
// Send an encrypted email.
CkEmail email;
email.put_Body("This is the encrypted email body");
email.put_FromAddress("matt@chilkatsoft.com");
email.put_Subject("This is the email subject");
// Load a certificate from a file and use it for encrypting.
CkCert cert;
cert.LoadFromFile("myCert.cer");
// The To address must match the email address in the certificate:
email.AddTo("Chilkat Support","support@chilkatsoft.com");
// Check to make sure the certificate's email address matches.
CkString certEmailAddr;
cert.get_SubjectE(certEmailAddr);
if (!certEmailAddr.equals("support@chilkatsoft.com"))
{
printf("Certificate email address (%s) does not match recipient's email address.\n",
certEmailAddr.getString());
return;
}
// To send an encrypted email, only the public-key is required.
// Use the certificate and indicate that the email should be encrypted.
email.put_SendEncrypted(true);
email.SetEncryptCert(&cert);
// Send the email
if (!mailman.SendEmail(&email))
{
mailman.SaveLastError("errors.xml");
}
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
freopen("stdout.txt","w",stdout);
EmailExample();
CkSettings::cleanupMemory();
_CrtDumpMemoryLeaks();
return 0;
}
Send Signed + Encrypted EmailSample C++ program to send signed and encrypted email.
#define _CRTDBG_MAP_ALLOC
#include
#include
#include
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkSettings.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkCert.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkEmail.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkEmailBundle.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkMailMan.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkString.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkByteData.h"
void EmailExample(void)
{
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
mailman.put_SmtpHost("mail.earthlink.net");
// Send a signed + encrypted email.
CkEmail email;
email.put_Body("This is the email body");
email.put_Subject("This is the email subject");
// Load certificates for signing and encrypting.
// The signing certificate must match the sender's email address.
// The encrypting certificate must match the recipient's email address.
CkCert cert1;
cert1.LoadFromFile("signingCert.cer");
CkCert cert2;
cert2.LoadFromFile("encryptCert.cer");
// The To address must match the email address in the encrypting certificate:
email.AddTo("Chilkat Support","support@chilkatsoft.com");
// The From address must match the email address in the signing certificate.
email.put_FromAddress("matt@chilkatsoft.com");
// Use the certificates ...
email.put_SendSigned(true);
email.SetSigningCert(&cert1);
email.put_SendEncrypted(true);
email.SetEncryptCert(&cert2);
// Send the signed + encrypted email
if (!mailman.SendEmail(&email))
{
mailman.SaveLastError("errors.xml");
}
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
freopen("stdout.txt","w",stdout);
EmailExample();
CkSettings::cleanupMemory();
_CrtDumpMemoryLeaks();
return 0;
}
Send Email with Return Receipt
Sample C++ program to send an email with a return-receipt.
#define _CRTDBG_MAP_ALLOC
#include
#include
#include
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkSettings.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkCert.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkEmail.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkEmailBundle.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkMailMan.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkString.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkByteData.h"
void EmailExample(void)
{
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
mailman.put_SmtpHost("mail.earthlink.net");
// Send an email with a return-receipt
CkEmail email;
// Set the ReturnReceipt property to true to request a Return Receipt.
email.put_ReturnReceipt(true);
email.put_Body("This is the email body");
email.put_Subject("This is the email subject");
email.AddTo("Chilkat Support","support@chilkatsoft.com");
email.put_FromAddress("matt@chilkatsoft.com");
// Send the email with a return receipt.
if (!mailman.SendEmail(&email))
{
mailman.SaveLastError("errors.xml");
}
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
freopen("stdout.txt","w",stdout);
EmailExample();
CkSettings::cleanupMemory();
_CrtDumpMemoryLeaks();
return 0;
}
Multiple CC Carbon Copy Recipients
Download
Chilkat C/C++ Libraries for VC++ 9.0 / Win32Download Chilkat C/C++ Libraries for VC++ 8.0 / Win32
Download Chilkat C/C++ 64-bit Libraries for VC++ 8.0 / x64
Download Chilkat Visual Studio 2005 C/C++ Libs for Windows Mobile, Pocket PC, SmartPhone, WinCE
Download Chilkat C/C++ Libraries for VC++ 7.0 / Win32
Download Chilkat C/C++ Libraries for VC++ 6.0 / Win32
Download Chilkat C/C++ Libraries for VC++ 6.0, Win 95/98/NT4 Compatible
Sample C++ program to send an email with multiple CC recipients.
#define _CRTDBG_MAP_ALLOC
#include
#include
#include
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkSettings.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkCert.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkEmail.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkEmailBundle.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkMailMan.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkString.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkByteData.h"
void EmailExample(void)
{
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
mailman.put_SmtpHost("mail.earthlink.net");
// Send an email with multiple carbon-copy recipients
CkEmail email;
email.put_Body("This is the email body");
email.put_Subject("This is the email subject");
email.AddTo("Chilkat Support","support@chilkatsoft.com");
// Call AddCC multiple times to add any number of CC recipients.
email.AddCC("Chilkat Sales","sales@chilkatsoft.com");
email.AddCC("Info","info@chilkatsoft.com");
email.put_FromAddress("matt@chilkatsoft.com");
// Send the email
if (!mailman.SendEmail(&email))
{
mailman.SaveLastError("errors.xml");
}
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
freopen("stdout.txt","w",stdout);
EmailExample();
CkSettings::cleanupMemory();
_CrtDumpMemoryLeaks();
return 0;
}
Multiple BCC Blind Carbon Copy Recipients
Download
Chilkat C/C++ Libraries for VC++ 9.0 / Win32Download Chilkat C/C++ Libraries for VC++ 8.0 / Win32
Download Chilkat C/C++ 64-bit Libraries for VC++ 8.0 / x64
Download Chilkat Visual Studio 2005 C/C++ Libs for Windows Mobile, Pocket PC, SmartPhone, WinCE
Download Chilkat C/C++ Libraries for VC++ 7.0 / Win32
Download Chilkat C/C++ Libraries for VC++ 6.0 / Win32
Download Chilkat C/C++ Libraries for VC++ 6.0, Win 95/98/NT4 Compatible
Sample C++ program to send an email with multiple BCC recipients.
#define _CRTDBG_MAP_ALLOC
#include
#include
#include
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkSettings.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkCert.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkEmail.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkEmailBundle.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkMailMan.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkString.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkByteData.h"
void EmailExample(void)
{
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
mailman.put_SmtpHost("mail.earthlink.net");
// Send an email with multiple blind carbon-copy recipients
CkEmail email;
email.put_Body("This is the email body");
email.put_Subject("This is the email subject");
email.AddTo("Chilkat Support","support@chilkatsoft.com");
// Call AddBcc multiple times to add any number of BCC recipients.
email.AddBcc("Chilkat Sales","sales@chilkatsoft.com");
email.AddBcc("Info","info@chilkatsoft.com");
email.put_FromAddress("matt@chilkatsoft.com");
// Send the email
if (!mailman.SendEmail(&email))
{
mailman.SaveLastError("errors.xml");
}
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
freopen("stdout.txt","w",stdout);
EmailExample();
CkSettings::cleanupMemory();
_CrtDumpMemoryLeaks();
return 0;
}
Set a Bounce Address when Sending EmailSample C++ program to set a bounce address when sending email. Mail bounces will go to this email address.
#define _CRTDBG_MAP_ALLOC
#include
#include
#include
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkSettings.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkCert.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkEmail.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkEmailBundle.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkMailMan.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkString.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkByteData.h"
void EmailExample(void)
{
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
mailman.put_SmtpHost("mail.earthlink.net");
// Send an email with a bounce address different from the "From" address.
CkEmail email;
email.put_BounceAddress("bounce@chilkatsoft.com");
email.put_Body("This is the email body");
email.put_Subject("This is the email subject");
email.AddTo("Chilkat Support","support@chilkatsoft.com");
email.put_FromAddress("matt@chilkatsoft.com");
// Send the email
if (!mailman.SendEmail(&email))
{
mailman.SaveLastError("errors.xml");
}
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
freopen("stdout.txt","w",stdout);
EmailExample();
CkSettings::cleanupMemory();
_CrtDumpMemoryLeaks();
return 0;
}
Set a Reply-To Address when Sending Email
Sample C++ program to set a reply-to address when sending email. Replies will go to this email address instead of the "From" address.
#define _CRTDBG_MAP_ALLOC
#include
#include
#include
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkSettings.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkCert.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkEmail.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkEmailBundle.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkMailMan.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkString.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkByteData.h"
// Set a Reply-To email address that is different from the From address.
void EmailExample(void)
{
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
mailman.put_SmtpHost("mail.earthlink.net");
// Send an email with a Reply-To address different from the "From" address.
CkEmail email;
email.put_ReplyTo("reply@chilkatsoft.com");
email.put_Body("This is the email body");
email.put_Subject("This is the email subject");
email.AddTo("Chilkat Support","support@chilkatsoft.com");
email.put_FromAddress("matt@chilkatsoft.com");
// Send the email
if (!mailman.SendEmail(&email))
{
mailman.SaveLastError("errors.xml");
}
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
freopen("stdout.txt","w",stdout);
EmailExample();
CkSettings::cleanupMemory();
_CrtDumpMemoryLeaks();
return 0;
}
Send Email using iso-8859-1 EncodingSample C++ program to showing how to send email using the iso-8859-1 charset. This example uses characters with diacritics (accented characters) to show how Chilkat Email VC++ automatically handles encoding the email.
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
mailman.put_SmtpHost("mail.earthlink.net");
// Send an email using the iso-8859-1 charset encoding.
CkEmail email;
email.put_Body("This is the email body Û Ü Ý Þ ß à á â");
email.put_Subject("Û Ü Ý Þ ß à á â");
email.AddTo("Chilkat Þ ß Support","support@chilkatsoft.com");
email.put_FromName("ç è é ê ë");
email.put_FromAddress("matt@chilkatsoft.com");
email.put_Charset("iso-8859-1");
// Send the email
if (!mailman.SendEmail(&email))
{
mailman.SaveLastError("errors.xml");
}
*************
This is the MIME text of the email that is created and sent by this example:
MIME-Version: 1.0
Date: Fri, 20 Aug 2004 07:43:45 -0500
Message-ID:
X-Mailer: Chilkat Software Inc (http://www.chilkatsoft.com)
X-Priority: 3 (Normal)
Content-Transfer-Encoding: quoted-printable
subject: =?iso-8859-1?Q?=DB_=DC_=DD_=DE_=DF_=E0_=E1_=E2?=
To: =?iso-8859-1?Q?Chilkat_=DE_=DF_Support?=
From: =?iso-8859-1?Q?=E7_=E8_=E9_=EA_=EB?=
return-path: matt@chilkatsoft.com
Content-Type: text/plain;
charset="iso-8859-1"
This is the email body =DB =DC =DD =DE =DF =E0 =E1 =E2
Send Email using utf-8 Encoding
Sample C++ program to showing how to send email using the utf-8 charset. The only difference between this example and the example to send iso-8859-1 is that the Charset property is set to "utf-8". Notice how the email that is constructed is very different.
// Send an email using the utf-8 character encoding
void EmailExample(void)
{
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
mailman.put_SmtpHost("mail.earthlink.net");
// Send an email using the utf-8 charset encoding.
CkEmail email;
email.put_Body("This is the email body Û Ü Ý Þ ß à á â");
email.put_Subject("Û Ü Ý Þ ß à á â");
email.AddTo("Chilkat Þ ß Support","support@chilkatsoft.com");
email.put_FromName("ç è é ê ë");
email.put_FromAddress("matt@chilkatsoft.com");
email.put_Charset("utf-8");
// Send the email
if (!mailman.SendEmail(&email))
{
mailman.SaveLastError("errors.xml");
}
}
****************
The MIME text of the email created by this example looks like this:
MIME-Version: 1.0
Date: Fri, 20 Aug 2004 07:49:32 -0500
Message-ID:
X-Mailer: Chilkat Software Inc (http://www.chilkatsoft.com)
X-Priority: 3 (Normal)
Content-Transfer-Encoding: quoted-printable
subject: =?utf-8?B?w5sgw5wgw50gw54gw58gw6Agw6Egw6I=?=
To: =?utf-8?B?Q2hpbGthdCDDniDDnyBTdXBwb3J0?=
From: =?utf-8?B?w6cgw6ggw6kgw6ogw6s=?=
return-path: matt@chilkatsoft.com
Content-Type: text/plain; charset="utf-8"
This is the email body =C3=9B =C3=9C =C3=9D =C3=9E =C3=9F =C3=A0 =C3=A1 =
=C3=A2
Send a Chinese Email
Sample C++ program to showing how to send an email in Chinese.
// Send a Chinese email
void EmailExample(void)
{
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
mailman.put_SmtpHost("mail.earthlink.net");
CkEmail email;
// Load a utf-8 text file containing Chinese characters.
// Our sample text file contains this text: xxxx
CkString str;
str.loadFile("chinese.txt","utf-8");
// Set the email's multibyte string mode to "utf-8"
// After doing this, all "const char *" method arguments expect
// utf-8 strings.
email.put_Utf8(true);
email.put_Body(str.getUtf8());
email.put_Subject(str.getUtf8());
email.AddTo("Chilkat Support","support@chilkatsoft.com");
email.put_FromName("Matt");
email.put_FromAddress("matt@chilkatsoft.com");
// We can explicitly set the charset by setting the Charset property.
// However, Chilkat is smart in that it automatically recognizes the
// Chinese characters and sets the charset appropriately.
// email.put_Charset("big5");
// email.put_Charset("gb2312");
// Send the email
if (!mailman.SendEmail(&email))
{
mailman.SaveLastError("errors.xml");
}
}
*******
The MIME source of the email created by this example looks like this:
MIME-Version: 1.0
Date: Fri, 20 Aug 2004 08:04:22 -0500
Message-ID:
X-Mailer: Chilkat Software Inc (http://www.chilkatsoft.com)
X-Priority: 3 (Normal)
Content-Type: text/plain; charset="gb2312"
Content-Transfer-Encoding: base64
subject: =?gb2312?B?ztLE3M3Mz8Kyo8Gntviyu4L7ye3zd6Gj?=
To: "Chilkat Support"
From: "Matt"
return-path: matt@chilkatsoft.com
ztLE3M3Mz8Kyo8Gntviyu4L7ye3zd6Gj
Send Korean Email
This sample C++ program shows how to send an email in Korean.
// Send a Korean email
void EmailExample(void)
{
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
mailman.put_SmtpHost("mail.earthlink.net");
CkEmail email;
// Load a utf-8 text file containing these Korean characters: 나는 유리를 먹을 수 있어요.
CkString str;
str.loadFile("korean.txt","utf-8");
// Set the email's multibyte string mode to "utf-8"
// After doing this, all "const char *" method arguments expect
// utf-8 strings.
email.put_Utf8(true);
email.put_Body(str.getUtf8());
email.put_Subject(str.getUtf8());
email.AddTo("Chilkat Support","support@chilkatsoft.com");
email.put_FromName("Matt");
email.put_FromAddress("matt@chilkatsoft.com");
// We can explicitly set the charset by setting the Charset property.
// However, Chilkat is smart in that it automatically recognizes the
// Korean characters and sets the charset appropriately.
// email.put_Charset("ks_c_5601-1987");
// email.put_Charset("iso-2022-kr");
// Send the email
if (!mailman.SendEmail(&email))
{
mailman.SaveLastError("errors.xml");
}
}
*****
The MIME source of the email created by Chilkat looks is this:
MIME-Version: 1.0
Date: Fri, 20 Aug 2004 08:26:10 -0500
Message-ID:
X-Mailer: Chilkat Software Inc (http://www.chilkatsoft.com)
X-Priority: 3 (Normal)
Content-Type: text/plain; charset="ks_c_5601-1987"
Content-Transfer-Encoding: base64
subject: =?ks_c_5601-1987?B?s6q0wiDAr7iuuKYguNTAuyC89iA=?=
=?ks_c_5601-1987?B?wNa+7r/kLg==?=
To: "Chilkat Support"
From: "Matt"
return-path: matt@chilkatsoft.com
s6q0wiDAr7iuuKYguNTAuyC89iDA1r7uv+Qu
Send Japanese Mail
C++ source code to send Japanese email.
// C++ Code to Send Japanese Mail
void EmailExample(void)
{
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
mailman.put_SmtpHost("mail.earthlink.net");
CkEmail email;
// Load a utf-8 text file containing Japanese text.
// The Japanese text is: 私はガラスを食べられます。
CkString str;
str.loadFile("japanese.txt","utf-8");
// Set the email's multibyte string mode to "utf-8"
// After doing this, all "const char *" method arguments expect
// utf-8 strings.
email.put_Utf8(true);
email.put_Body(str.getUtf8());
email.put_Subject(str.getUtf8());
email.AddTo("Chilkat Support","support@chilkatsoft.com");
email.put_FromName("Matt");
email.put_FromAddress("matt@chilkatsoft.com");
// We can explicitly set the charset by setting the Charset property.
// However, Chilkat is smart in that it automatically recognizes the
// Japanese characters and sets the charset appropriately.
// email.put_Charset("Shift_JIS");
// email.put_Charset("iso-2022-jp");
// email.put_Charset("euc-jp");
// Send the email
if (!mailman.SendEmail(&email))
{
mailman.SaveLastError("errors.xml");
}
}
****
The MIME source of the email created by this program is:
MIME-Version: 1.0
Date: Fri, 20 Aug 2004 11:09:59 -0500
Message-ID:
X-Mailer: Chilkat Software Inc (http://www.chilkatsoft.com)
X-Priority: 3 (Normal)
Content-Type: text/plain; charset="shift_jis"
Content-Transfer-Encoding: base64
subject: =?shift_jis?B?joSCzYNLg4mDWILwkEiC14LnguqC3IK3?=
=?shift_jis?B?gUI=?=
To: "Chilkat Support"
From: "Matt"
return-path: matt@chilkatsoft.com
joSCzYNLg4mDWILwkEiC14LnguqC3IK3gUI=
Send a Russian EmailThis C++ program creates and sends an email in Russian.
// C++ Code to Send Russian Mail
void EmailExample(void)
{
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
mailman.put_SmtpHost("mail.earthlink.net");
CkEmail email;
// Load a utf-8 text file containing Russian text.
// The Russian text is: На берегу пустынных волн
CkString str;
str.loadFile("russian.txt","utf-8");
// Set the email's multibyte string mode to "utf-8"
// After doing this, all "const char *" method arguments expect
// utf-8 strings.
email.put_Utf8(true);
email.put_Body(str.getUtf8());
email.put_Subject(str.getUtf8());
email.AddTo("Chilkat Support","support@chilkatsoft.com");
email.put_FromName("Matt");
email.put_FromAddress("matt@chilkatsoft.com");
// We can explicitly set the charset by setting the Charset property.
// However, Chilkat is smart in that it automatically recognizes the
// Russian characters and sets the charset appropriately.
// email.put_Charset("koi8-r");
// email.put_Charset("iso-8859-5");
// email.put_Charset("windows-1251");
// Send the email
if (!mailman.SendEmail(&email))
{
mailman.SaveLastError("errors.xml");
}
}
*****
The MIME text of the email created and sent by this program is:
MIME-Version: 1.0
Date: Fri, 20 Aug 2004 11:21:25 -0500
Message-ID:
X-Mailer: Chilkat Software Inc (http://www.chilkatsoft.com)
X-Priority: 3 (Normal)
Content-Type: text/plain;
charset="iso-8859-5"
Content-Transfer-Encoding: quoted-printable
subject: =?iso-8859-5?Q?=BD=D0_=D1=D5=E0=D5=D3=E3_=DF=E3=E1=E2=EB=DD=DD=EB=E5_=D2=DE=DB=DD?=
To: "Chilkat Support"
From: "Matt"
return-path: matt@chilkatsoft.com
=BD=D0 =D1=D5=E0=D5=D3=E3 =DF=E3=E1=E2=EB=DD=DD=EB=E5 =D2=DE=DB=DD
Send a Thai Email
This C++ program creates and sends an email in Thai.
// C++ Code to Send Thai Mail
void EmailExample(void)
{
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
mailman.put_SmtpHost("mail.earthlink.net");
CkEmail email;
// Load a utf-8 text file containing Thai text.
// The Thai text is: ฉันกินกระจกได้ แต่มันไม่ทำให้ฉันเจ็บ
CkString str;
str.loadFile("thai.txt","utf-8");
// Set the email's multibyte string mode to "utf-8"
// After doing this, all "const char *" method arguments expect
// utf-8 strings.
email.put_Utf8(true);
email.put_Body(str.getUtf8());
email.put_Subject(str.getUtf8());
email.AddTo("Chilkat Support","support@chilkatsoft.com");
email.put_FromName("Matt");
email.put_FromAddress("matt@chilkatsoft.com");
// We can explicitly set the charset by setting the Charset property.
// However, Chilkat is smart in that it automatically recognizes the
// Thai characters and sets the charset appropriately.
// email.put_Charset("windows-874");
// Send the email
if (!mailman.SendEmail(&email))
{
mailman.SaveLastError("errors.xml");
}
}
*****
The MIME text of the email created and sent by this program is:
MIME-Version: 1.0
Date: Fri, 20 Aug 2004 11:26:21 -0500
Message-ID:
X-Mailer: Chilkat Software Inc (http://www.chilkatsoft.com)
X-Priority: 3 (Normal)
Content-Type: text/plain; charset="windows-874"
Content-Transfer-Encoding: base64
subject: =?windows-874?B?qdG5odS5ocPQqKHk?=
=?windows-874?B?tOkg4bXowdG55MHo?=
=?windows-874?B?t9Pjy+mp0bngqOe6?=
To: "Chilkat Support"
From: "Matt"
return-path: matt@chilkatsoft.com
qdG5odS5ocPQqKHktOkg4bXowdG55MHot9Pjy+mp0bngqOe6
Send a Vietnamese Email
This C++ program creates and sends an email in Vietnamese.
// Send Vietnamese Email in C++
void EmailExample(void)
{
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
mailman.put_SmtpHost("mail.earthlink.net");
CkEmail email;
// Load a utf-8 text file containing Vietnamese text.
// The Vietnamese text is: Tôi có thể ăn thủy tinh mà không hại gì.
CkString str;
str.loadFile("vietnamese.txt","utf-8");
// Set the email's multibyte string mode to "utf-8"
// After doing this, all "const char *" method arguments expect
// utf-8 strings.
email.put_Utf8(true);
email.put_Body(str.getUtf8());
email.put_Subject(str.getUtf8());
email.AddTo("Chilkat Support","support@chilkatsoft.com");
email.put_FromName("Matt");
email.put_FromAddress("matt@chilkatsoft.com");
// Vietnamese email is sent using the utf-8 character encoding.
email.put_Charset("utf-8");
// Send the email
if (!mailman.SendEmail(&email))
{
mailman.SaveLastError("errors.xml");
}
}
*****
The MIME text of the email created and sent by this program is:
MIME-Version: 1.0
Date: Fri, 20 Aug 2004 11:35:15 -0500
Message-ID:
X-Mailer: Chilkat Software Inc (http://www.chilkatsoft.com)
X-Priority: 3 (Normal)
Content-Transfer-Encoding: base64
subject: =?utf-8?B?VMO0aSBjw7MgdGjhu4MgxIM=?=
=?utf-8?B?biB0aOG7p3kgdGluaCA=?=
=?utf-8?B?bcOgIGtow7RuZyBo4bqhaQ==?=
=?utf-8?B?IGfDrC4=?=
To: "Chilkat Support"
From: "Matt"
return-path: matt@chilkatsoft.com
Content-Type: text/plain; charset="utf-8"
77u/VMO0aSBjw7MgdGjhu4MgxINuIHRo4buneSB0aW5oIG3DoCBraMO0bmcgaOG6oWkgZ8Os
Lg==
Send a Georgian EmailThis C++ program creates and sends an email in Georgian.
// Send Georgian Email in C++
void EmailExample(void)
{
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
mailman.put_SmtpHost("mail.earthlink.net");
CkEmail email;
// Load a utf-8 text file containing Georgian text.
// The Georgian text is: ვეპხის ტყაოსანი შოთა რუსთაველი
CkString str;
str.loadFile("georgian.txt","utf-8");
// Set the email's multibyte string mode to "utf-8"
// After doing this, all "const char *" method arguments expect
// utf-8 strings.
email.put_Utf8(true);
email.put_Body(str.getUtf8());
email.put_Subject(str.getUtf8());
email.AddTo("Chilkat Support","support@chilkatsoft.com");
email.put_FromName("Matt");
email.put_FromAddress("matt@chilkatsoft.com");
// Georgian email is sent using the utf-8 character encoding.
email.put_Charset("utf-8");
// Send the email
if (!mailman.SendEmail(&email))
{
mailman.SaveLastError("errors.xml");
}
}
*****
The MIME text of the email created and sent by this program is:
MIME-Version: 1.0
Date: Fri, 20 Aug 2004 11:41:18 -0500
Message-ID:
X-Mailer: Chilkat Software Inc (http://www.chilkatsoft.com)
X-Priority: 3 (Normal)
Content-Transfer-Encoding: base64
subject: =?utf-8?B?4YOV4YOU4YOe4YOu4YOY4YOhIOGDouGDp+GDkOGDneGDoQ==?=
=?utf-8?B?4YOQ4YOc4YOYIOGDqOGDneGDl+GDkCDhg6Dhg6Phg6E=?=
=?utf-8?B?4YOX4YOQ4YOV4YOU4YOa4YOY?=
To: "Chilkat Support"
From: "Matt"
return-path: matt@chilkatsoft.com
Content-Type: text/plain; charset="utf-8"
77u/4YOV4YOU4YOe4YOu4YOY4YOhIOGDouGDp+GDkOGDneGDoeGDkOGDnOGDmCDhg6jhg53h
g5fhg5Ag4YOg4YOj4YOh4YOX4YOQ4YOV4YOU4YOa4YOY
Send a Hindi Email
This C++ program creates and sends an email in Hindi.
// Send Hindi Email in C++
void EmailExample(void)
{
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
mailman.put_SmtpHost("mail.earthlink.net");
CkEmail email;
// Load a utf-8 text file containing Hindi text.
// The Hindi text is: मैं काँच खा सकता हूँ, मुझे उस से कोई पीडा नहीं होती.
CkString str;
str.loadFile("hindi.txt","utf-8");
// Set the email's multibyte string mode to "utf-8"
// After doing this, all "const char *" method arguments expect
// utf-8 strings.
email.put_Utf8(true);
email.put_Body(str.getUtf8());
email.put_Subject(str.getUtf8());
email.AddTo("Chilkat Support","support@chilkatsoft.com");
email.put_FromName("Matt");
email.put_FromAddress("matt@chilkatsoft.com");
// Hindi email is sent using the utf-8 character encoding.
email.put_Charset("utf-8");
// Send the email
if (!mailman.SendEmail(&email))
{
mailman.SaveLastError("errors.xml");
}
}
*****
The MIME text of the email created and sent by this program is:
MIME-Version: 1.0
Date: Fri, 20 Aug 2004 11:44:34 -0500
Message-ID:
X-Mailer: Chilkat Software Inc (http://www.chilkatsoft.com)
X-Priority: 3 (Normal)
Content-Transfer-Encoding: base64
subject: =?utf-8?B?4KSu4KWI4KSCIOCkleCkvuCkgeCkmiDgpJbgpL4g?=
=?utf-8?B?4KS44KSV4KSk4KS+IOCkueClguCkgSwg4KSu4KWB?=
=?utf-8?B?4KSd4KWHIOCkieCkuCDgpLjgpYcg4KSV4KWL4KSI?=
=?utf-8?B?IOCkquClgOCkoeCkviDgpKjgpLngpYDgpIIg4KS5?=
=?utf-8?B?4KWL4KSk4KWALg==?=
To: "Chilkat Support"
From: "Matt"
return-path: matt@chilkatsoft.com
Content-Type: text/plain; charset="utf-8"
77u/4KSu4KWI4KSCIOCkleCkvuCkgeCkmiDgpJbgpL4g4KS44KSV4KSk4KS+IOCkueClguCk
gSwg4KSu4KWB4KSd4KWHIOCkieCkuCDgpLjgpYcg4KSV4KWL4KSIIOCkquClgOCkoeCkviDg
pKjgpLngpYDgpIIg4KS54KWL4KSk4KWALg==
Send HTML Email with Embedded Image
Demonstrates how to send an HTML email with an embedded image.
// Send HTML email with an embedded image.
void EmailExample(void)
{
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
mailman.put_SmtpHost("mail.earthlink.net");
CkEmail email;
CkString strHtml;
strHtml.append("Embedded Image:
");
// Insert the image into the email, returning the CID
CkString strCid;
if (!email.AddRelatedFile("dude.gif",&strCid))
{
printf("Failed to add image to email.\n");
email.SaveLastError("error.xml");
return;
}
// Update the HTML to reference the image using the CID
strHtml.replaceFirstOccurance("IMAGE_CID",strCid.getString());
// Set the HTML body.
email.SetHtmlBody(strHtml.getString());
email.put_Subject("HTML mail with embedded image");
email.AddTo("Chilkat Support","support@chilkatsoft.com");
email.put_FromName("Matt");
email.put_FromAddress("matt@chilkatsoft.com");
// Send the email
if (!mailman.SendEmail(&email))
{
mailman.SaveLastError("errors.xml");
}
}
Send Email to Distribution List using Mail Merge
Demonstrates how to send email to a distribution list with mail merge.
// Send email to distribution list using mail-merge
void EmailExample(void)
{
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
mailman.put_SmtpHost("mail.earthlink.net");
// Create an array of email addresses.
// This is where you might load email addresses from a file,
// or load email addresses from a database such as Access, SQL Server, Oracle, MySQL, etc.
CkStringArray array;
array.put_Unique(true); // Do not allow duplicates in the array.
// Chilkat will be able to parse the full email addresses...
array.Append("Chilkat Support ");
array.Append("\"Chilkat Sales\" ");
array.Append("");
array.Append("joe@chilkatsoft.com");
CkEmail email;
// Make this email have both HTML and plain-text alternatives.
// Be sure to use CRLF line endings in plain-text email.
email.AddPlainTextAlternativeBody("Hello CUSTOMER_NAME\r\nThis is a test");
email.AddHtmlAlternativeBody("Hello CUSTOMER_NAME
This is a test");
email.put_Subject("CUSTOMER_NAME: This is a test.");
email.put_FromName("Bob");
email.put_FromAddress("bob@chilkatsoft.com");
int i;
int numEmails = array.get_Count();
CkString friendlyName;
for (i=0; i
{
email.ClearTo();
// We call AddMultipleTo even though we are only adding a single
// email address. AddMultipleTo parses a comma separated list of
// email addresses, each of which may or may not include the
// friendly name.
email.AddMultipleTo(array.GetString(i));
// Get the friendly name that was in the email address.
email.GetToName(0,friendlyName);
if (!friendlyName.getNumChars())
{
friendlyName.append("Customer");
}
// Set the replacement pattern. When the email is sent, all occurances of
// CUSTOMER_NAME are replaced with the replacement string.
email.SetReplacePattern("CUSTOMER_NAME",friendlyName.getString());
// The email can have any number of replacement patterns. Simply
// set a replace pattern for each.
// email.SetReplacePattern("PATTERN2","replacement2");
// email.SetReplacePattern("PATTERN3","replacement3");
bool sendQueued = true;
// One option is to send the email in the background using the SMTPQ service:
if (sendQueued)
{
// Sending the email using SMTPQ allows for emails to be sent by multiple
// threads simultaneously by the SMTPQ process. The email sending will
// also survive system reboots / crashes because it will resume when the
// service restarts on system startup.
if (!mailman.SendQ(&email))
{
// We could send the email in-process:
mailman.SaveLastError("errors.xml");
break;
}
}
else
{
// Or... the mail can be sent in-process.
if (!mailman.SendEmail(&email))
{
// We could send the email in-process:
mailman.SaveLastError("errors.xml");
break;
}
}
}
}
Add In-Memory Data as Email AttachmentHow to add an email attachment directly from in-memory data.
// Add in-memory data as an attachment to an email.
void EmailExample(void)
{
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
mailman.put_SmtpHost("mail.earthlink.net");
CkEmail email;
email.put_Body("This is a test");
email.put_Subject("This is the subject.");
email.put_FromName("Bob");
email.put_FromAddress("bob@chilkatsoft.com");
email.AddTo("Chilkat Support","support@chilkatsoft.com");
const char *myText = "This will by my text file attachment\nEmail is easy!\n";
email.AddDataAttachment("MyText.txt",(const unsigned char *)myText,strlen(myText));
if (!mailman.SendEmail(&email))
{
// We could send the email in-process:
mailman.SaveLastError("errors.xml");
}
}
Send 168-bit 3DES Encrypted Email
Demonstrates how to send 3DES encrypted mail.
// Send a 3DES encrypted email
void EmailExample(void)
{
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
mailman.put_SmtpHost("mail.earthlink.net");
// Send a 3DES 168-bit encrypted email.
CkEmail email;
email.put_Body("This is the encrypted email body");
email.put_FromAddress("matt@chilkatsoft.com");
email.put_Subject("This is the email subject");
// Load a certificate from a file and use it for encrypting.
CkCert cert;
cert.LoadFromFile("myCert.cer");
// The To address must match the email address in the certificate:
email.AddTo("Chilkat Support","support@chilkatsoft.com");
// Check to make sure the certificate's email address matches.
CkString certEmailAddr;
cert.get_SubjectE(certEmailAddr);
if (!certEmailAddr.equals("support@chilkatsoft.com"))
{
printf("Certificate email address (%s) does not match recipient's email address.\n",
certEmailAddr.getString());
return;
}
// To send an encrypted email, only the public-key is required.
// Use the certificate and indicate that the email should be encrypted.
email.put_SendEncrypted(true);
email.SetEncryptCert(&cert);
// Use 3DES encryption.
CkCSP csp;
csp.SetProviderMicrosoftEnhanced();
csp.SetEncryptAlgorithm("3DES");
email.SetCSP(&csp);
// Send the email
if (!mailman.SendEmail(&email))
{
mailman.SaveLastError("errors.xml");
}
else
{
// The last error information will also contain information
// about how the email was encrypted when successful, so you can
// verify that what you expected to happen actually did happen.
mailman.SaveLastError("info.xml");
}
}
************************
The info.xml file will look something like this:
Connecting to SMTP server mail.earthlink.net:25
mail.earthlink.net
25
NULL
NONE
NONE or already authenticated
CONNECTED to ESMTP server mail.earthlink.net:25
3DES
Using explicit certificate.
Thawte Freemail Member, support@chilkatsoft.com
Matt Fausey
Microsoft Enhanced Cryptographic Provider v1.0
3DES
168
1.2.840.113549.3.7
This is the email subject
matt@chilkatsoft.com
support@chilkatsoft.com
1622
Mail sent to 1 recipient
Read Mail from POP3 Leaving it on the Server
Download
Chilkat C/C++ Libraries for VC++ 9.0 / Win32Download Chilkat C/C++ Libraries for VC++ 8.0 / Win32
Download Chilkat C/C++ 64-bit Libraries for VC++ 8.0 / x64
Download Chilkat Visual Studio 2005 C/C++ Libs for Windows Mobile, Pocket PC, SmartPhone, WinCE
Download Chilkat C/C++ Libraries for VC++ 7.0 / Win32
Download Chilkat C/C++ Libraries for VC++ 6.0 / Win32
Download Chilkat C/C++ Libraries for VC++ 6.0, Win 95/98/NT4 Compatible
Demonstrates how to read email from a POP3 server, leaving it on the server.
// The Chilkat Mail library is also available as an ActiveX component
// or .NET class with the identical set of methods and properties.
// Read POP3 email, leaving it on the server.
void EmailExample(void)
{
CkString str;
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
mailman.put_MailHost("mail.chilkatsoft.com");
mailman.put_PopUsername("matt");
mailman.put_PopPassword(myPassword);
CkEmailBundle *bundle = 0;
// Copy email from the POP3 server, leaving it on the server.
bundle = mailman.CopyMail();
if (!bundle)
{
mailman.LastErrorText(str);
printf("%s",str.getString());
return;
}
int i;
int n = bundle->get_MessageCount();
for (i=0; i
{
CkEmail *email = bundle->GetEmail(i);
email->get_Subject(str);
printf("Subject: %s\n",str.getString());
email->get_From(str);
printf("From: %s\n",str.getString());
// Gets the default body. If multipart/alternative where both
// HTML and plain-text bodies are present, the HTML body is retrieved.
email->get_Body(str);
printf("Body -----------\n%s\n---------------\n",str.getString());
delete email;
}
delete bundle;
return;
}
POP3 SSL - Read POP3 Email Using SSLDemonstrates how to read email from an SSL POP3 server. When connecting to POP3 SSL Exchange Server, use port 995.
// The Chilkat Mail library is also available as an ActiveX component
// or .NET class with the identical set of methods and properties.
// Read POP3 email from MS Exchange Server using SSL
void EmailExample(void)
{
CkString str;
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
mailman.put_MailHost("mail.chilkatsoft.com");
mailman.put_PopUsername("matt");
mailman.put_PopPassword(myPassword);
// Set the POP3 port to the standard MS Exchange Server SSL POP3 port 995
mailman.put_MailPort(995);
// Tell the mailman to connect to POP3 using SSL
mailman.put_PopSsl(true);
CkEmailBundle *bundle = 0;
// Copy email from the POP3 server, leaving it on the server.
bundle = mailman.CopyMail();
if (!bundle)
{
mailman.LastErrorText(str);
printf("%s",str.getString());
return;
}
int i;
int n = bundle->get_MessageCount();
for (i=0; i
{
CkEmail *email = bundle->GetEmail(i);
email->get_Subject(str);
printf("Subject: %s\n",str.getString());
email->get_From(str);
printf("From: %s\n",str.getString());
// Gets the default body. If multipart/alternative where both
// HTML and plain-text bodies are present, the HTML body is retrieved.
email->get_Body(str);
printf("Body -----------\n%s\n---------------\n",str.getString());
delete email;
}
delete bundle;
return;
}
Set POP3 Connect and Read Timeout Parameters
Demonstrates how to set POP3 timeout values for reading email.
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
mailman.put_MailHost("mail.chilkatsoft.com");
mailman.put_PopUsername("matt");
mailman.put_PopPassword(myPassword);
// Set the POP3 port to the standard MS Exchange Server SSL POP3 port 995
// mailman.put_MailPort(995);
// Tell the mailman to connect to POP3 using SSL
// mailman.put_PopSsl(true);
// Set the POP3 connect timeout to 5 seconds
mailman.put_ConnectTimeout(5);
// Set the POP3 read timeout to 10 seconds.
mailman.put_ReadTimeout(10);
...
Download POP3 Email
Download
Chilkat C/C++ Libraries for VC++ 9.0 / Win32Download Chilkat C/C++ Libraries for VC++ 8.0 / Win32
Download Chilkat C/C++ 64-bit Libraries for VC++ 8.0 / x64
Download Chilkat Visual Studio 2005 C/C++ Libs for Windows Mobile, Pocket PC, SmartPhone, WinCE
Download Chilkat C/C++ Libraries for VC++ 7.0 / Win32
Download Chilkat C/C++ Libraries for VC++ 6.0 / Win32
Download Chilkat C/C++ Libraries for VC++ 6.0, Win 95/98/NT4 Compatible
C++ code to download email from a POP3 mail server.
// The Chilkat Email library is also available as an ActiveX component
// or .NET class with the identical set of methods and properties.
// Download POP3 email to your local computer.
void EmailExample(void)
{
CkString str;
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
mailman.put_MailHost("mail.chilkatsoft.com");
mailman.put_PopUsername("matt");
mailman.put_PopPassword(myPassword);
// Set the POP3 port to the standard MS Exchange Server SSL POP3 port 995
// mailman.put_MailPort(995);
// Tell the mailman to connect to POP3 using SSL
// mailman.put_PopSsl(true);
CkEmailBundle *bundle = 0;
// Use TransferMail to download email from the POP3 server,
// removing it from the POP3 server.
bundle = mailman.TransferMail();
if (!bundle)
{
mailman.LastErrorText(str);
printf("%s",str.getString());
return;
}
int i;
int n = bundle->get_MessageCount();
for (i=0; i
{
CkEmail *email = bundle->GetEmail(i);
email->get_Subject(str);
printf("Subject: %s\n",str.getString());
email->get_From(str);
printf("From: %s\n",str.getString());
// Gets the default body. If multipart/alternative where both
// HTML and plain-text bodies are present, the HTML body is retrieved.
email->get_Body(str);
printf("Body -----------\n%s\n---------------\n",str.getString());
delete email;
}
delete bundle;
return;
}
Download POP3 Email HeadersC++ code to download email headers from a POP3 mail server.
// The Chilkat Email library is also available as an ActiveX component
// or .NET class with the identical set of methods and properties.
// Fetch POP3 email headers
void EmailExample(void)
{
CkString str;
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
mailman.put_MailHost("mail.chilkatsoft.com");
mailman.put_PopUsername("matt");
mailman.put_PopPassword(myPassword);
// Set the POP3 port to the standard MS Exchange Server SSL POP3 port 995
// mailman.put_MailPort(995);
// Tell the mailman to connect to POP3 using SSL
// mailman.put_PopSsl(true);
CkEmailBundle *bundle = 0;
// Use GetAllHeaders to fetch each email header and the 1st N lines of
// the body from a POP3 server.
// Note: Attachment information will not be available. This is a shortfall
// of the POP3 protocol because attachment information is not included
// in POP3 headers. An entire POP3 email must be read in order to get complete
// attachment information.
bundle = mailman.GetAllHeaders(2); // Get 2 body lines...
if (!bundle)
{
mailman.LastErrorText(str);
printf("%s",str.getString());
return;
}
int i;
int n = bundle->get_MessageCount();
for (i=0; i
{
CkEmail *email = bundle->GetEmail(i);
email->get_Subject(str);
printf("Subject: %s\n",str.getString());
email->get_From(str);
printf("From: %s\n",str.getString());
delete email;
}
delete bundle;
return;
}
Fetch POP3 email headers with filtering (PayPal example)
Download
Chilkat C/C++ Libraries for VC++ 9.0 / Win32Download Chilkat C/C++ Libraries for VC++ 8.0 / Win32
Download Chilkat C/C++ 64-bit Libraries for VC++ 8.0 / x64
Download Chilkat Visual Studio 2005 C/C++ Libs for Windows Mobile, Pocket PC, SmartPhone, WinCE
Download Chilkat C/C++ Libraries for VC++ 7.0 / Win32
Download Chilkat C/C++ Libraries for VC++ 6.0 / Win32
Download Chilkat C/C++ Libraries for VC++ 6.0, Win 95/98/NT4 Compatible
C++ code to download email headers matching a filter.
// The Chilkat Email library is also available as an ActiveX component
// or .NET class with the identical set of methods and properties.
// Fetch POP3 email headers with filtering.
// This example fetches PayPal payment notification email messages.
void EmailExample(void)
{
CkString str;
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
mailman.put_MailHost("mail.chilkatsoft.com");
mailman.put_PopUsername("matt");
mailman.put_PopPassword(myPassword);
// Set the POP3 port to the standard MS Exchange Server SSL POP3 port 995
// mailman.put_MailPort(995);
// Tell the mailman to connect to POP3 using SSL
// mailman.put_PopSsl(true);
// Set our filter to only return PayPal payment notification emails.
mailman.put_Filter("Subject like \"*Notification of Payment Received*\"");
// Use GetAllHeaders to fetch each email header and the 1st N lines of
// the body from a POP3 server.
CkEmailBundle *bundle = 0;
bundle = mailman.GetAllHeaders(2); // Get 2 body lines...
if (!bundle)
{
mailman.LastErrorText(str);
printf("%s",str.getString());
return;
}
int i;
int n = bundle->get_MessageCount();
for (i=0; i
{
CkEmail *email = bundle->GetEmail(i);
email->get_Subject(str);
printf("Subject: %s\n",str.getString());
email->get_From(str);
printf("From: %s\n",str.getString());
delete email;
}
delete bundle;
return;
}
Download Full Email after Downloading Email HeaderC++ code to download a full email with attachments after downloading the email header.
// The Chilkat Email library is also available as an ActiveX component
// or .NET class with the identical set of methods and properties.
// Fetch full email from POP3 server after fetching the header.
void EmailExample(void)
{
CkString str;
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
mailman.put_MailHost("mail.chilkatsoft.com");
mailman.put_PopUsername("matt");
mailman.put_PopPassword(myPassword);
// Set the POP3 port to the standard MS Exchange Server SSL POP3 port 995
// mailman.put_MailPort(995);
// Tell the mailman to connect to POP3 using SSL
// mailman.put_PopSsl(true);
// Use GetAllHeaders to fetch each email header and the 1st N lines of
// the body from a POP3 server.
CkEmailBundle *bundle = 0;
bundle = mailman.GetAllHeaders(2); // Get 2 body lines...
if (!bundle)
{
mailman.LastErrorText(str);
printf("%s",str.getString());
return;
}
int i;
int n = bundle->get_MessageCount();
// Download the full email for the first header in the bundle:
if (n > 0)
{
CkEmail *email = bundle->GetEmail(0);
// Now get the email with full body and attachments.
CkEmail *fullEmail = mailman.GetFullEmail(email);
// Save the full email as XML.
if (fullEmail)
{
fullEmail->SaveXml("fullEmail.xml");
}
else
{
mailman.LastErrorText(str);
printf("%s",str.getString());
}
delete fullEmail;
delete email;
}
delete bundle;
Check Number of Messages on POP3 Server
Download
Chilkat C/C++ Libraries for VC++ 9.0 / Win32Download Chilkat C/C++ Libraries for VC++ 8.0 / Win32
Download Chilkat C/C++ 64-bit Libraries for VC++ 8.0 / x64
Download Chilkat Visual Studio 2005 C/C++ Libs for Windows Mobile, Pocket PC, SmartPhone, WinCE
Download Chilkat C/C++ Libraries for VC++ 7.0 / Win32
Download Chilkat C/C++ Libraries for VC++ 6.0 / Win32
Download Chilkat C/C++ Libraries for VC++ 6.0, Win 95/98/NT4 Compatible
C++ code to check for email on a POP3 server.
// The Chilkat Email library is also available as an ActiveX component
// or .NET class with the identical set of methods and properties.
// Check to see how many emails are on the POP3 server.
void EmailExample(void)
{
CkString str;
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
mailman.put_MailHost("mail.chilkatsoft.com");
mailman.put_PopUsername("matt");
mailman.put_PopPassword(myPassword);
// Set the POP3 port to the standard MS Exchange Server SSL POP3 port 995
// mailman.put_MailPort(995);
// Tell the mailman to connect to POP3 using SSL
// mailman.put_PopSsl(true);
int numEmailMessages = mailman.CheckMail();
if (numEmailMessages == -1)
{
mailman.LastErrorText(str);
printf("%s",str.getString());
}
else
{
printf("There are %d mail messages on the POP3 server.\n",numEmailMessages);
}
Verify POP3 LoginSource code to verify a POP3 login.
// The Chilkat Email library is also available as an ActiveX component
// or .NET class with the identical set of methods and properties.
// Verify a POP3 login
void EmailExample(void)
{
CkString str;
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
mailman.put_MailHost("mail.chilkatsoft.com");
mailman.put_PopUsername("matt");
mailman.put_PopPassword(myPassword);
// Set the POP3 port to the standard MS Exchange Server SSL POP3 port 995
// mailman.put_MailPort(995);
// Tell the mailman to connect to POP3 using SSL
// mailman.put_PopSsl(true);
// Verify the POP3 login.
bool success = mailman.VerifyPopLogin();
if (!success)
{
mailman.LastErrorText(str);
printf("%s",str.getString());
}
Verify POP3 TCP/IP Connection
Source code to verify that it is possible to connect to a POP3 server.
// The Chilkat Email library is also available as an ActiveX component
// or .NET class with the identical set of methods and properties.
// Verify a POP3 TCP/IP socket connection.
void EmailExample(void)
{
CkString str;
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
// Set the POP3 port to the standard MS Exchange Server SSL POP3 port 995
// mailman.put_MailPort(995);
// Tell the mailman to connect to POP3 using SSL
// mailman.put_PopSsl(true);
// Verify the POP3 TCP/IP connection.
bool success = mailman.VerifyPopConnection();
if (!success)
{
mailman.LastErrorText(str);
printf("%s",str.getString());
}
Delete a single email from a POP3 server.
Download
Chilkat C/C++ Libraries for VC++ 9.0 / Win32Download Chilkat C/C++ Libraries for VC++ 8.0 / Win32
Download Chilkat C/C++ 64-bit Libraries for VC++ 8.0 / x64
Download Chilkat Visual Studio 2005 C/C++ Libs for Windows Mobile, Pocket PC, SmartPhone, WinCE
Download Chilkat C/C++ Libraries for VC++ 7.0 / Win32
Download Chilkat C/C++ Libraries for VC++ 6.0 / Win32
Download Chilkat C/C++ Libraries for VC++ 6.0, Win 95/98/NT4 Compatible
Source code to delete a single email from a POP3 server.
// The Chilkat Email library is also available as an ActiveX component
// or .NET class with the identical set of methods and properties.
// Delete a single email from a POP3 server.
void EmailExample(void)
{
CkString str;
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
// Set the POP3 port to the standard MS Exchange Server SSL POP3 port 995
// mailman.put_MailPort(995);
// Tell the mailman to connect to POP3 using SSL
// mailman.put_PopSsl(true);
mailman.put_MailHost("mail.chilkatsoft.com");
mailman.put_PopUsername("matt");
mailman.put_PopPassword(myPassword);
// Use GetAllHeaders to fetch each email header and the 1st N lines of
// the body from a POP3 server.
CkEmailBundle *bundle = 0;
bundle = mailman.GetAllHeaders(2); // Get 2 body lines...
if (!bundle)
{
mailman.LastErrorText(str);
printf("%s",str.getString());
return;
}
int i;
int n = bundle->get_MessageCount();
for (i=0; i
{
CkEmail *email = bundle->GetEmail(i);
email->get_Subject(str);
printf("Subject: %s\n",str.getString());
if (str.containsSubstringNoCase("Xanax"))
{
// Delete this email from the POP3 server.
// Each mailman method call is a separate POP3 connection,
// so a more efficient means of deleting multiple emails
// is to call DeleteMultiple (see example for deleting multiple emails).
mailman.DeleteEmail(email);
// We could also do this:
// CkString strUidl;
// email->get_Uidl(strUidl);
// mailman.DeleteByUidl(strUidl.getString());
}
delete email;
}
delete bundle;
return;
}
Delete a multiple emails from a POP3 server.
Download
Chilkat C/C++ Libraries for VC++ 9.0 / Win32Download Chilkat C/C++ Libraries for VC++ 8.0 / Win32
Download Chilkat C/C++ 64-bit Libraries for VC++ 8.0 / x64
Download Chilkat Visual Studio 2005 C/C++ Libs for Windows Mobile, Pocket PC, SmartPhone, WinCE
Download Chilkat C/C++ Libraries for VC++ 7.0 / Win32
Download Chilkat C/C++ Libraries for VC++ 6.0 / Win32
Download Chilkat C/C++ Libraries for VC++ 6.0, Win 95/98/NT4 Compatible
Source code to delete a multiple emails from a POP3 server.
// The Chilkat Email library is also available as an ActiveX component
// or .NET class with the identical set of methods and properties.
// Delete multiple emails from a POP3 server.
void EmailExample(void)
{
CkString str;
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
// Set the POP3 port to the standard MS Exchange Server SSL POP3 port 995
// mailman.put_MailPort(995);
// Tell the mailman to connect to POP3 using SSL
// mailman.put_PopSsl(true);
mailman.put_MailHost("mail.chilkatsoft.com");
mailman.put_PopUsername("matt");
mailman.put_PopPassword(myPassword);
// Use GetAllHeaders to fetch each email header and the 1st N lines of
// the body from a POP3 server.
CkEmailBundle *bundle = 0;
bundle = mailman.GetAllHeaders(2); // Get 2 body lines...
if (!bundle)
{
mailman.LastErrorText(str);
printf("%s",str.getString());
return;
}
int i;
int n = bundle->get_MessageCount();
CkStringArray uidlArray;
for (i=0; i
{
CkEmail *email = bundle->GetEmail(i);
email->get_Subject(str);
printf("Subject: %s\n",str.getString());
if (str.containsSubstringNoCase("Xanax") ||
str.containsSubstringNoCase("Viagra") ||
str.containsSubstringNoCase("Cialis"))
{
// Add this email to the list to be deleted.
email->get_Uidl(str);
uidlArray.Append(str.getString());
}
delete email;
}
// Now delete all the matching emails.
bool success = mailman.DeleteMultiple(&uidlArray);
if (!success)
{
mailman.LastErrorText(str);
printf("%s",str.getString());
}
delete bundle;
return;
}
Get Email Attachment Filename and Size Information
Download
Chilkat C/C++ Libraries for VC++ 9.0 / Win32Download Chilkat C/C++ Libraries for VC++ 8.0 / Win32
Download Chilkat C/C++ 64-bit Libraries for VC++ 8.0 / x64
Download Chilkat Visual Studio 2005 C/C++ Libs for Windows Mobile, Pocket PC, SmartPhone, WinCE
Download Chilkat C/C++ Libraries for VC++ 7.0 / Win32
Download Chilkat C/C++ Libraries for VC++ 6.0 / Win32
Download Chilkat C/C++ Libraries for VC++ 6.0, Win 95/98/NT4 Compatible
Source code to iterate over email attachments and display the filename and size.
// The Chilkat Email library is also available as an ActiveX component
// or .NET class with the identical set of methods and properties.
// Display email attachment information
void EmailExample(void)
{
CkString str;
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
// Set the POP3 port to the standard MS Exchange Server SSL POP3 port 995
// mailman.put_MailPort(995);
// Tell the mailman to connect to POP3 using SSL
// mailman.put_PopSsl(true);
mailman.put_MailHost("mail.chilkatsoft.com");
mailman.put_PopUsername("matt");
mailman.put_PopPassword(myPassword);
// Download email from the POP3 server.
CkEmailBundle *bundle = 0;
bundle = mailman.CopyMail();
if (!bundle)
{
mailman.LastErrorText(str);
printf("%s",str.getString());
return;
}
int i;
int n = bundle->get_MessageCount();
for (i=0; i
{
CkEmail *email = bundle->GetEmail(i);
int numAttach = email->get_NumAttachments();
printf("Number of attachments = %d\n",numAttach);
int j;
for (j=0; j
{
email->GetAttachmentFilename(j,str);
printf(" %d) filename = %s\n",j,str.getString());
printf(" %d) size = %d\n",j,email->GetAttachmentSize(j));
}
delete email;
}
delete bundle;
return;
}
Save Email Attachments to DiskExample source code to save email attachments to disk.
// The Chilkat Email library is also available as an ActiveX component
// or .NET class with the identical set of methods and properties.
// C++ showing how to save attachments to disk.
void EmailExample(void)
{
CkString str;
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
// Set the POP3 port to the standard MS Exchange Server SSL POP3 port 995
// mailman.put_MailPort(995);
// Tell the mailman to connect to POP3 using SSL
// mailman.put_PopSsl(true);
mailman.put_MailHost("mail.chilkatsoft.com");
mailman.put_PopUsername("matt");
mailman.put_PopPassword(myPassword);
// Download email from the POP3 server.
CkEmailBundle *bundle = 0;
bundle = mailman.CopyMail();
if (!bundle)
{
mailman.LastErrorText(str);
printf("%s",str.getString());
return;
}
int i;
int n = bundle->get_MessageCount();
for (i=0; i
{
CkEmail *email = bundle->GetEmail(i);
int numAttach = email->get_NumAttachments();
printf("Number of attachments = %d\n",numAttach);
int j;
for (j=0; j
{
// Save the attachment to disk.
// If the attachment filename is identical to an already existing file,
// Chilkat automatically changes the attachment filename to a unique name.
// The actual filename saved to disk is available after saving.
bool saveSuccess = email->SaveAttachedFile(j,"attachmentsDir");
if (!saveSuccess)
{
email->LastErrorText(str);
printf("%s",str.getString());
}
else
{
email->GetAttachmentFilename(j,str);
printf(" %d) saved to filename: %s\n",j,str.getString());
}
}
delete email;
}
delete bundle;
return;
}
Save All Email Attachments to a DirectoryExample source code to save all email attachments to a directory.
// The Chilkat Email library is also available as an ActiveX component
// or .NET class with the identical set of methods and properties.
// Save all attachments to disk.
void EmailExample(void)
{
CkString str;
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
// Set the POP3 port to the standard MS Exchange Server SSL POP3 port 995
// mailman.put_MailPort(995);
// Tell the mailman to connect to POP3 using SSL
// mailman.put_PopSsl(true);
mailman.put_MailHost("mail.chilkatsoft.com");
mailman.put_PopUsername("matt");
mailman.put_PopPassword(myPassword);
// Download email from the POP3 server.
CkEmailBundle *bundle = 0;
bundle = mailman.CopyMail();
if (!bundle)
{
mailman.LastErrorText(str);
printf("%s",str.getString());
return;
}
int i;
int n = bundle->get_MessageCount();
for (i=0; i
{
CkEmail *email = bundle->GetEmail(i);
int numAttach = email->get_NumAttachments();
printf("Number of attachments = %d\n",numAttach);
// Save all the attachments to a directory
email->SaveAllAttachments("c:/attachments");
// Now display the actual filenames of the attachments saved to disk
int j;
for (j=0; j
{
// The filename returned by GetAttachmentFilename will not contain
// the directory path. When Chilkat saves attachments, if a file
// of the same name already exists, Chilkat will modify the attachment
// filename to make it unique so nothing is overwritten. After saving
// attachments, the GetAttachmentFilename method returns the name of
// the file saved.
email->GetAttachmentFilename(j,str);
printf(" %d) saved to filename: %s\n",j,str.getString());
}
delete email;
}
delete bundle;
return;
}
Iterate and Display Email Header FieldsExample source code to iterate over an email's header fields and print each name/value pair.
// The Chilkat Mail library is also available as an ActiveX component
// or .NET class with the identical set of methods and properties.
// Iterate over an email's header fields.
void EmailExample(void)
{
CkString str;
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
// Set the POP3 port to the standard MS Exchange Server SSL POP3 port 995
// mailman.put_MailPort(995);
// Tell the mailman to connect to POP3 using SSL
// mailman.put_PopSsl(true);
mailman.put_MailHost("mail.chilkatsoft.com");
mailman.put_PopUsername("matt");
mailman.put_PopPassword(myPassword);
// Copy email from the POP3 server.
CkEmailBundle *bundle = 0;
bundle = mailman.CopyMail();
if (!bundle)
{
mailman.LastErrorText(str);
printf("%s",str.getString());
return;
}
int i;
int n = bundle->get_MessageCount();
for (i=0; i
{
CkEmail *email = bundle->GetEmail(i);
printf("********* Email %d ***********\n",i);
int numFields = email->get_NumHeaderFields();
// Display each header field.
int j;
CkString strName;
CkString strValue;
for (j=0; j
{
email->GetHeaderFieldName(j,strName);
email->GetHeaderFieldValue(j,strValue);
printf("%s: [%s]\n",strName.getString(),strValue.getString());
}
delete email;
}
delete bundle;
return;
}
Save Email to .eml File
Example source code to save emails to .EML files.
// The Chilkat Mail library is also available as an ActiveX component
// or .NET class with the identical set of methods and properties.
// Download and save emails to .eml files.
void EmailExample(void)
{
CkString str;
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
// Set the POP3 port to the standard MS Exchange Server SSL POP3 port 995
// mailman.put_MailPort(995);
// Tell the mailman to connect to POP3 using SSL
// mailman.put_PopSsl(true);
mailman.put_MailHost("mail.chilkatsoft.com");
mailman.put_PopUsername("matt");
mailman.put_PopPassword(myPassword);
// Copy email from the POP3 server.
CkEmailBundle *bundle = 0;
bundle = mailman.CopyMail();
if (!bundle)
{
mailman.LastErrorText(str);
printf("%s",str.getString());
return;
}
int i;
int n = bundle->get_MessageCount();
for (i=0; i
{
CkEmail *email = bundle->GetEmail(i);
char fname[50];
sprintf(fname,"email_%d.eml",i);
// If you want to be able to edit the email in Outlook Express,
// add the X-Unsent header:
email->AddHeaderField("X-Unsent","1");
email->SaveEml(fname);
delete email;
}
delete bundle;
return;
}
Save Email in XML Format
Example source code to save emails in XML format.
// The Chilkat Mail library is also available as an ActiveX component
// or .NET class with the identical set of methods and properties.
// Save email in XML format.
void EmailExample(void)
{
CkString str;
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
// Set the POP3 port to the standard MS Exchange Server SSL POP3 port 995
// mailman.put_MailPort(995);
// Tell the mailman to connect to POP3 using SSL
// mailman.put_PopSsl(true);
mailman.put_MailHost("mail.chilkatsoft.com");
mailman.put_PopUsername("matt");
mailman.put_PopPassword(myPassword);
// Copy email from the POP3 server.
CkEmailBundle *bundle = 0;
bundle = mailman.CopyMail();
if (!bundle)
{
mailman.LastErrorText(str);
printf("%s",str.getString());
return;
}
int i;
int n = bundle->get_MessageCount();
for (i=0; i
{
CkEmail *email = bundle->GetEmail(i);
char fname[50];
sprintf(fname,"email_%d.xml",i);
email->SaveXml(fname);
delete email;
}
delete bundle;
return;
}
Convert Email to XML
Download
Chilkat C/C++ Libraries for VC++ 9.0 / Win32Download Chilkat C/C++ Libraries for VC++ 8.0 / Win32
Download Chilkat C/C++ 64-bit Libraries for VC++ 8.0 / x64
Download Chilkat Visual Studio 2005 C/C++ Libs for Windows Mobile, Pocket PC, SmartPhone, WinCE
Download Chilkat C/C++ Libraries for VC++ 7.0 / Win32
Download Chilkat C/C++ Libraries for VC++ 6.0 / Win32
Download Chilkat C/C++ Libraries for VC++ 6.0, Win 95/98/NT4 Compatible
Example source code to convert an email to an XML document.
// The Chilkat Mail library is also available as an ActiveX component
// or .NET class with the identical set of methods and properties.
// Convert email to an XML document
void EmailExample(void)
{
CkString str;
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
// Set the POP3 port to the standard MS Exchange Server SSL POP3 port 995
// mailman.put_MailPort(995);
// Tell the mailman to connect to POP3 using SSL
// mailman.put_PopSsl(true);
mailman.put_MailHost("mail.chilkatsoft.com");
mailman.put_PopUsername("matt");
mailman.put_PopPassword(myPassword);
// Copy email from the POP3 server.
CkEmailBundle *bundle = 0;
bundle = mailman.CopyMail();
if (!bundle)
{
mailman.LastErrorText(str);
printf("%s",str.getString());
return;
}
int i;
int n = bundle->get_MessageCount();
CkXml xml;
for (i=0; i
{
CkEmail *email = bundle->GetEmail(i);
// Get the email as XML.
email->GetXml(str);
// Using the Chilkat XML parser, display the email subject.
xml.LoadXml(str.getString());
xml.SearchForTag2(0,"subject");
xml.get_Content(str);
printf("subject: [%s]\n",str.getString());
delete email;
}
delete bundle;
return;
}
Unzip Email Attachments In-MemoryExample source code to unzip email attachments in-memory.
// The Chilkat Mail library is also available as an ActiveX component
// or .NET class with the identical set of methods and properties.
// Unzip email attachments in-memory
void EmailExample(void)
{
CkString str;
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
// Set the POP3 port to the standard MS Exchange Server SSL POP3 port 995
// mailman.put_MailPort(995);
// Tell the mailman to connect to POP3 using SSL
// mailman.put_PopSsl(true);
mailman.put_MailHost("mail.chilkatsoft.com");
mailman.put_PopUsername("matt");
mailman.put_PopPassword(myPassword);
// Copy email from the POP3 server.
CkEmailBundle *bundle = 0;
bundle = mailman.CopyMail();
if (!bundle)
{
mailman.LastErrorText(str);
printf("%s",str.getString());
return;
}
int i;
int n = bundle->get_MessageCount();
CkXml xml;
for (i=0; i
{
CkEmail *email = bundle->GetEmail(i);
// Unzip all the attachments that are Zip files.
// For example, if an email had to attachments named a.zip and b.zip,
// and a.zip contains the files 1.txt and 2.txt, and b.zip contains
// the files a.txt and b.txt, then ... after calling UnzipAttachments
// the email will contain 4 attachments: 1.txt, 2.txt, a.txt, and b.txt.
email->UnzipAttachments();
// Now save all the unzipped attachments to disk.
email->SaveAllAttachments("c:/attachments");
delete email;
}
delete bundle;
return;
}
Unobfuscate SPAM Email
Example source code to unobfuscate SPAM email by removing all HTML comments and unobfuscating hyperlinked URLs.
// The Chilkat Mail library is also available as an ActiveX component
// or .NET class with the identical set of methods and properties.
// Unobfuscate SPAM Email
void EmailExample(void)
{
CkString str;
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
// Set the POP3 port to the standard MS Exchange Server SSL POP3 port 995
// mailman.put_MailPort(995);
// Tell the mailman to connect to POP3 using SSL
// mailman.put_PopSsl(true);
mailman.put_MailHost("mail.chilkatsoft.com");
mailman.put_PopUsername("matt");
mailman.put_PopPassword(myPassword);
// Copy email from the POP3 server.
CkEmailBundle *bundle = 0;
bundle = mailman.CopyMail();
if (!bundle)
{
mailman.LastErrorText(str);
printf("%s",str.getString());
return;
}
int i;
int n = bundle->get_MessageCount();
CkXml xml;
for (i=0; i
{
CkEmail *email = bundle->GetEmail(i);
// Unobfuscate SPAM Email:
// Remove comments from the HTML body if the email contains HTML.
// Unobfuscate hyperlinked URLs contained in HTML tags.
email->UnSpamify();
// Save the email to a .eml file.
// A .eml is simply the full MIME text of the email,
// so you can edit it with any text editor to view
// the email source, or you can view the email
// in Outlook Express by double-clicking on the .eml file.
char fname[50];
sprintf(fname,"email_%d.eml",i);
email->SaveEml(fname);
delete email;
}
delete bundle;
return;
}
Verify Email Digital SignatureExample source code to verify the digital signature of a signed email.
// The Chilkat Mail library is also available as an ActiveX component
// or .NET class with the identical set of methods and properties.
// Verify email digital signatures
void EmailExample(void)
{
CkString str;
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
// Set the POP3 port to the standard MS Exchange Server SSL POP3 port 995
// mailman.put_MailPort(995);
// Tell the mailman to connect to POP3 using SSL
// mailman.put_PopSsl(true);
mailman.put_MailHost("mail.chilkatsoft.com");
mailman.put_PopUsername("matt");
mailman.put_PopPassword(myPassword);
// Copy email from the POP3 server.
CkEmailBundle *bundle = 0;
bundle = mailman.CopyMail();
if (!bundle)
{
mailman.LastErrorText(str);
printf("%s",str.getString());
return;
}
int i;
int n = bundle->get_MessageCount();
CkXml xml;
for (i=0; i
{
CkEmail *email = bundle->GetEmail(i);
// The mailman automatically "unwraps" security layers when
// downloading email. This functionality can be turned off
// by calling mailman.put_AutoUnwrapSecurity(false);
// However, for this example, we leave the default setting of "true",
// which means that the signature verification information is
// already present in the email, and the email has already been
// transformed to the state it was before being signed.
// Did we receive a signed email?
if (email->get_ReceivedSigned())
{
// If so, check to make sure the signature was verified.
if (email->get_SignaturesValid())
{
printf("Digital signature is valid, the email has not been modified.\n");
// Get the certificate that was used for signing.
CkCert *cert = email->GetSignedByCert();
if (cert)
{
cert->get_SubjectDN(str);
printf("Certificate: %s\n",str.getString());
delete cert;
}
else
{
printf("Failed to get certificate used for signing.\n");
}
}
else
{
printf("Digital signature was invalid\n");
}
}
delete email;
}
delete bundle;
return;
}
Read encrypted email from POP3 server and decrypt.
Download
Chilkat C/C++ Libraries for VC++ 9.0 / Win32Download Chilkat C/C++ Libraries for VC++ 8.0 / Win32
Download Chilkat C/C++ 64-bit Libraries for VC++ 8.0 / x64
Download Chilkat Visual Studio 2005 C/C++ Libs for Windows Mobile, Pocket PC, SmartPhone, WinCE
Download Chilkat C/C++ Libraries for VC++ 7.0 / Win32
Download Chilkat C/C++ Libraries for VC++ 6.0 / Win32
Download Chilkat C/C++ Libraries for VC++ 6.0, Win 95/98/NT4 Compatible
Visual C++ example program to read encrypted email from a POP3 server and decrypt.
// The Chilkat Mail library is also available as an ActiveX component
// or .NET class with the identical set of methods and properties.
// Read encrypted email from POP3 server and decrypt.
void EmailExample(void)
{
CkString str;
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
// Set the POP3 port to the standard MS Exchange Server SSL POP3 port 995
// mailman.put_MailPort(995);
// Tell the mailman to connect to POP3 using SSL
// mailman.put_PopSsl(true);
mailman.put_MailHost("mail.chilkatsoft.com");
mailman.put_PopUsername("matt");
mailman.put_PopPassword(myPassword);
// Copy email from the POP3 server.
CkEmailBundle *bundle = 0;
bundle = mailman.CopyMail();
if (!bundle)
{
mailman.LastErrorText(str);
printf("%s",str.getString());
return;
}
int i;
int n = bundle->get_MessageCount();
CkXml xml;
for (i=0; i
{
CkEmail *email = bundle->GetEmail(i);
// The mailman automatically "unwraps" security layers when
// downloading email. This functionality can be turned off
// by calling mailman.put_AutoUnwrapSecurity(false);
// However, for this example, we leave the default setting of "true",
// which means that the encryption information is
// already present in the email, and the email has already been
// decrypted to the state it was before being encrypted.
// Did we receive an encrypted email?
if (email->get_ReceivedEncrypted())
{
// If so, check to make sure the email was decrypted
if (email->get_Decrypted())
{
printf("Email has been decrypted.\n");
// Get the certificate that was used for encryption.
CkCert *cert = email->GetEncryptedByCert();
if (cert)
{
cert->get_SubjectDN(str);
printf("Certificate: %s\n",str.getString());
delete cert;
}
else
{
printf("Failed to get certificate used for encryption.\n");
}
}
else
{
printf("Failed to decrypt\n");
}
}
delete email;
}
delete bundle;
return;
}
Clone an Email Object
Download
Chilkat C/C++ Libraries for VC++ 9.0 / Win32Download Chilkat C/C++ Libraries for VC++ 8.0 / Win32
Download Chilkat C/C++ 64-bit Libraries for VC++ 8.0 / x64
Download Chilkat Visual Studio 2005 C/C++ Libs for Windows Mobile, Pocket PC, SmartPhone, WinCE
Download Chilkat C/C++ Libraries for VC++ 7.0 / Win32
Download Chilkat C/C++ Libraries for VC++ 6.0 / Win32
Download Chilkat C/C++ Libraries for VC++ 6.0, Win 95/98/NT4 Compatible
Show how to create an exact duplicate of an email object.
...
// Clone an email object.
CkEmail *email = bundle->GetEmail(i);
// Any email object can be cloned:
CkEmail *clonedEmail = email->Clone();
Get Linked Domains in HTML EmailShow how to retrieve the hyperlinked domains found in an HTML email.
// The Chilkat Mail library is also available as an ActiveX component
// or .NET class with the identical set of methods and properties.
void EmailExample(void)
{
CkString str;
CkMailMan mailman;
// Any string passed to UnlockComponent begins the 30-day trial.
bool unlocked = mailman.UnlockComponent("30-day trial");
if (!unlocked)
{
printf("Failed to unlock component\n");
return;
}
// Set the POP3 port to the standard MS Exchange Server SSL POP3 port 995
// mailman.put_MailPort(995);
// Tell the mailman to connect to POP3 using SSL
// mailman.put_PopSsl(true);
mailman.put_MailHost("mail.chilkatsoft.com");
mailman.put_PopUsername("matt");
mailman.put_PopPassword(myPassword);
// Copy email from the POP3 server.
CkEmailBundle *bundle = 0;
bundle = mailman.CopyMail();
if (!bundle)
{
mailman.LastErrorText(str);
printf("%s",str.getString());
return;
}
int i;
int n = bundle->get_MessageCount();
CkStringArray array;
for (i=0; i
{
CkEmail *email = bundle->GetEmail(i);
// Get the domain names that were contained in HTML hyperlinks in the email.
array.Clear();
email->GetLinkedDomains(array);
printf("Email #%d\n",i);
int j;
int m = array.get_Count();
for (j=0; j
{
// Print each domain, such as "http://www.yahoo.com"
printf(" %s\n",array.GetString(j));
}
delete email;
}
delete bundle;
return;
}
Read POP3 Mailbox with Progress Monitoring
Download
Chilkat C/C++ Libraries for VC++ 9.0 / Win32Download Chilkat C/C++ Libraries for VC++ 8.0 / Win32
Download Chilkat C/C++ 64-bit Libraries for VC++ 8.0 / x64
Download Chilkat Visual Studio 2005 C/C++ Libs for Windows Mobile, Pocket PC, SmartPhone, WinCE
Download Chilkat C/C++ Libraries for VC++ 7.0 / Win32
Download Chilkat C/C++ Libraries for VC++ 6.0 / Win32
Download Chilkat C/C++ Libraries for VC++ 6.0, Win 95/98/NT4 Compatible
To read a POP3 mailbox with progress monitoring, create a class that inherits CkMailProgress and provide implementations for the ReadPercentDone, SendPercentDone, and AbortCheck methods.
class MyMailProgress : public CkMailProgress
{
void ReadPercentDone(long pctDone, bool *abort)
{
printf("Read %d Percent Done!\n",pctDone);
// Set *abort = true to cause the read to abort
}
void SendPercentDone(long pctDone, bool *abort)
{
printf("Send %d Percent Done!\n",pctDone);
// Set *abort = true to cause the send to abort
}
// Called periodically to check to see if the transfer (read or send) should be aborted.
void AbortCheck(bool *abort)
{
printf("Abort Check!\n");
}
};
void TestReadEmail(void)
{
CkMailMan mailman;
mailman.UnlockComponent("test");
mailman.put_PopPassword("****");
mailman.put_PopUsername("****");
mailman.put_MailHost("mail.chilkatsoft.com");
MyMailProgress myProgress;
mailman.SetProgressCallback(&myProgress);
CkEmailBundle *bundle = mailman.CopyMail();
if (bundle)
{
int n = bundle->get_MessageCount();
for (int i = 0; i < n; i++)
{
CkEmail *email = bundle->GetEmail(i);
...
}
delete bundle;
}
return;
}
Send Signed Email in HebrewSend a digitally signed email in Hebrew using the utf-8 character encoding.
// Send a digitally signed Hebrew email using utf-8.
void SendSignedHebrew(void)
{
CkMailMan mailman;
mailman.UnlockComponent("anything for 30-day unlock code");
mailman.put_SmtpHost("smtp.comcast.net");
// Load a text file containing one line of utf-8 text in Hebrew.
// The hebrewSample.txt file can be downloaded from http://www.chilkatsoft.com/testData/hebrewSample.txt
CkString str;
str.put_Utf8(true);
str.loadFile("hebrewSample.txt","utf-8");
CkEmail email;
// This is the charset to be used when sending the email.
email.put_Charset("utf-8");
// This indicates that string (const char *) arguments
// will be passed in the utf-8 encoding.
email.put_Utf8(true);
email.put_Subject(str.getUtf8());
email.put_Body(str.getUtf8());
email.put_From("admin@tagtooga.com");
email.AddTo("Chilkat Support","support@chilkatsoft.com");
email.put_SendSigned(true);
bool success = mailman.SendEmail(&email);
if (!success)
{
mailman.SaveLastError("errorLog.txt");
}
}
Parsing Delivery Status Notification (DSN)
This C++ example code demonstrates how to parse a DSN email.
void TestParseDsn(void)
{
// How to parse a DSN Email
// (Parsing a Delivery Status Notification Email)
// Unlock the components that are needed for this example:
CkMailMan mailman0;
mailman0.UnlockComponent("30-day trial");
CkMime mime0;
mime0.UnlockComponent("30-day trial");
// Load a .eml file into the email object.
// A zip containing 10 DSN sample emails can be found at:
// http://www.chilkatsoft.com/dsn_samples/DSN_Samples.zip
CkEmail email;
email.LoadEml("dsnSample2.eml");
// The email should be a multipart/report. If not, exit.
if (!email.IsMultipartReport())
{
printf("Not a DSN!\n");
return;
}
// The overall format of a DSN is described here:
// http://www.chilkatsoft.com/braindump/email_headers/mime_format_dsn.html
//
// In summary, the outermost MIME layer is a multipart/report,
// and 3 parts are contained within:
// 1) A human-readable explanation of the DSN (content-type is text/plain)
// 2) A message/delivery-status part.
// 3) The original email (message/rfc822) or the headers of the original
// email (text/rfc822-headers)
// The human-readable part of the DSN is accessible via the email's Body property:
CkString strBody;
email.get_Body(strBody);
printf("Body:\n%s\n---------------------------------------\n\n",strBody.getString());
// To parse the message/delivery-status part, we need Chilkat Mime.
// Get the email as a MIME object:
CkMime *pmime = email.GetMimeObject();
CkMime &mime = *pmime;
// Now get the message/delivery-status part.
// It is the 2nd sub-part, so the index is 1.
CkMime *pdstat = mime.GetPart(1);
CkMime &dstat = *pdstat;
// Do we have what we expect?
CkString strContentType;
dstat.get_ContentType(strContentType);
if (strContentType.equalsIgnoreCase("message/delivery-status"))
{
// The body of the message/delivery-status contains MIME headers.
// There is a single per-message header set, and 1 or more
// per-recipient header sets.
// For example, this one has 2 recipients:
//
//Reporting-MTA: dns; comcast.net
//Arrival-Date: 13 Sep 2006 23:28:50 +0000
//
//Final-Recipient: rfc822;
//Action: failed
//Status: 5.0.0 550_Requested_action_not_taken:_mailbox_unavailable_or_not_local
//Diagnostic-Code: smtp; Permanent Failure: Other undefined Status
//Last-Attempt-Date: Wed, 13 Sep 2006 23:28:51 -0000
//
//Final-Recipient: rfc822;
//Action: failed
//Status: 5.0.0 550_Requested_action_not_taken:_mailbox_unavailable_or_not_local
//Diagnostic-Code: smtp; Permanent Failure: Other undefined Status
//Last-Attempt-Date: Wed, 13 Sep 2006 23:28:51 -0000
// How do we parse it???
// We'll let CkMime do the work. First, we'll get the body and then
// split it into separate chunks where each is then treated as a separate
// MIME message with an empty body.
dstat.GetBodyDecoded(strBody);
// The CkStringArray class includes the SplitAndAppend method to
// split a string using boundary strings. If we split at double-CRLF's
// we can get each chunk.
// Note: The SplitAndAppend is new to CkStringArray (14-Sep-2006). If it is not present
// in your existing libs, download the latest from http://www.chilkatsoft.com/downloads.asp
CkStringArray sa;
sa.SplitAndAppend(strBody.getString(), "\r\n\r\n");
printf("count = %d\n",sa.get_Count());
// Display each set of headers...
int i;
for (i=0; i
{
printf("[%s]\n\n",sa.GetString(i));
}
// The 1st header-set contains the Reporting-MTA.
// Load it and
CkMime mTemp;
CkString strMime;
strMime.append(sa.GetString(0));
strMime.append("\r\n\r\n");
mTemp.LoadMime(strMime.getString());
CkString strValue;
// Print the Reporting-MTA
mTemp.GetHeaderField("Reporting-MTA",strValue);
printf("Reporting-MTA: %s\n",strValue.getString());
// Print the Arrival-Date
mTemp.GetHeaderField("Arrival-Date",strValue);
printf("Arrival-Date: %s\n",strValue.getString());
printf("--\n\n");
// Print information for each Final-Recipient
for (i=1; i
{
mTemp.LoadMime(sa.GetString(i));
// (Not all of these fields may be present.)
// Information about Final-Recipient is located here:
// http://chilkatsoft.com/braindump/email_headers/Final-Recipient_header.html
mTemp.GetHeaderField("Final-Recipient",strValue);
printf("Final-Recipient: %s\n",strValue.getString());
// Information about the Action header field is located at:
// http://chilkatsoft.com/braindump/email_headers/action_dsn_header_field.html
mTemp.GetHeaderField("Action",strValue);
printf("Action: %s\n",strValue.getString());
// Information about the Status header field is located at:
// http://chilkatsoft.com/braindump/email_headers/status_dsn_header_field.html
mTemp.GetHeaderField("Status",strValue);
printf("Status: %s\n",strValue.getString());
// Information about the Diagnostic-Code header field is located at:
// http://chilkatsoft.com/braindump/email_headers/diagnostic-code_header_field.html
mTemp.GetHeaderField("Diagnostic-Code",strValue);
printf("Diagnostic-Code: %s\n",strValue.getString());
mTemp.GetHeaderField("Last-Attempt-Date",strValue);
printf("Last-Attempt-Date: %s\n",strValue.getString());
mTemp.GetHeaderField("Remote-MTA",strValue);
printf("Remote-MTA: %s\n",strValue.getString());
printf("--\n\n");
}
}
else
{
dstat.get_ContentType(strContentType);
printf("Unexpected delivery status, content-type = %s\n",strContentType.getString());
}
// The original email is available as an embedded message:
CkEmail *originalEmail = email.GetAttachedMessage(0);
// If the original email is Nothing, then the DSN only included the original
// email headers as a text/rfc822-headers
if (originalEmail)
{
// We got the original email. Because it is a ChilkatEmail2 object,
// the headers, bodies, attachments, etc, are all accessible.
// This example will simply save the original email to a file.
originalEmail->SaveEml("originalEmail.eml");
}
else
{
// The DSN did not have the complete message/rfc822 attached.
// Use Chilkat Mime to see what we have...
// (The DSN samples at http://www.chilkatsoft.com/dsn_samples/DSN_Samples.zip
// include a DSN (sampleEml10.eml) that uses a text/rfc822-headers.)
// Access the email via the ChilkatMime API:
CkMime *origMime = email.GetMimeObject();
// Now get the 3rd sub-part, which is at index 2.
CkMime *part3 = origMime->GetPart(2);
// Make sure we have it...
if (!part3)
{
delete origMime;
delete pmime;
delete pdstat;
printf("Did not get sub-part #3!\n");
return;
}
// Is this a text/rfc822-headers part?
part3->get_ContentType(strContentType);
if (strContentType.equalsIgnoreCase("text/rfc822-headers"))
{
// OK, the body of this part is a collection of headers.
// If we get the body, we can append a few blank lines
// and then read it as a MIME message and access any
// header.
CkString strMime;
part3->GetBodyDecoded(strMime);
strMime.append("\r\n\r\n");
// Load it into a MIME object.
CkMime mime2;
mime2.LoadMime(strMime.getString());
CkString strValue;
// Fetch some of the headers:
mime2.GetHeaderField("from",strValue);
printf("From: %s\n",strValue.getString());
mime2.GetHeaderField("subject",strValue);
printf("Subject: %s\n",strValue.getString());
mime2.GetHeaderField("to",strValue);
printf("To: %s\n",strValue.getString());
}
else
{
part3->get_ContentType(strContentType);
printf("Unexpected content-type: %s\n",strContentType.getString());
}
delete part3;
delete origMime;
}
delete pmime;
delete pdstat;
}
Check if an Email is a DSN
Download
Chilkat C/C++ Libraries for VC++ 9.0 / Win32Download Chilkat C/C++ Libraries for VC++ 8.0 / Win32
Download Chilkat C/C++ 64-bit Libraries for VC++ 8.0 / x64
Download Chilkat Visual Studio 2005 C/C++ Libs for Windows Mobile, Pocket PC, SmartPhone, WinCE
Download Chilkat C/C++ Libraries for VC++ 7.0 / Win32
Download Chilkat C/C++ Libraries for VC++ 6.0 / Win32
Download Chilkat C/C++ Libraries for VC++ 6.0, Win 95/98/NT4 Compatible
This C++ example code demonstrates how to check to see if an email is a DSN (Delivery Status Notification)
CkMailMan mailman0;
mailman0.UnlockComponent("30-day trial");
// Load a .eml file into the email object.
// A zip containing 10 DSN sample emails can be found at:
// http://www.chilkatsoft.com/dsn_samples/DSN_Samples.zip
CkEmail email;
email.LoadEml("dsnSample2.eml");
// The email should be a multipart/report. If not, exit.
if (!email.IsMultipartReport())
{
printf("Not a DSN!\n");
}
else
{
printf("Is a DSN!\n");
}
Create Forward with Original Email Attached
Download
Chilkat C/C++ Libraries for VC++ 9.0 / Win32Download Chilkat C/C++ Libraries for VC++ 8.0 / Win32
Download Chilkat C/C++ 64-bit Libraries for VC++ 8.0 / x64
Download Chilkat Visual Studio 2005 C/C++ Libs for Windows Mobile, Pocket PC, SmartPhone, WinCE
Download Chilkat C/C++ Libraries for VC++ 7.0 / Win32
Download Chilkat C/C++ Libraries for VC++ 6.0 / Win32
Download Chilkat C/C++ Libraries for VC++ 6.0, Win 95/98/NT4 Compatible
C++ example code to create a forwarding email with the original email attached as an rfc822/message.
// Demonstrates how to create a forward email
// with the original email attached.
void CreateForward(void)
{
CkMailMan mailman;
mailman.UnlockComponent("Anything for 30-day trial");
// This example loads an email from a .eml file. Your
// program might instead use an email object created
// by downloading email from a POP3 or IMAP server.
CkEmail email;
email.LoadEml("originalEmail.eml");
// I'm sorry to say we'll need some CkMime functionality to help...
CkMime mime;
mime.UnlockComponent("Anything for 30-day trialest");
// The goal here is to attach the original email as a message/rfc822
// Get the original email as a MIME object.
CkMime *originalEmailAsMimeObj = email.GetMimeObject();
// Create a new message/rfc822 MIME message, with a payload containing
// the original email.
mime.NewMessageRfc822(*originalEmailAsMimeObj);
// Create a new email -- anything we want...
CkEmail email2;
email2.put_Subject("This is a forwarded email, see attached message");
email2.AddTo("Matt", "matt@chilkatsoft.com");
email2.put_From("admin@chilkatsoft.com");
email2.AddPlainTextAlternativeBody("This is the plain-text alternative body of the forwarded email");
email2.AddHtmlAlternativeBody("This is the HTML alternative body of the forwarded email");
// We'll want to attach the original email to this email, but we really need Chilkat Mime to do it...
// So first convert email2 to a MIME object.
CkMime *email2Mime = email2.GetMimeObject();
// The "mime" variable contains our message/rfc822 MIME with the original email.
// Append it as a new sub-part to email2Mime
email2Mime->AppendPart(&mime);
// Load it back into email2.
CkString mimeStr;
email2Mime->GetMime(mimeStr);
email2.SetFromMimeText(mimeStr.getString());
delete email2Mime;
delete originalEmailAsMimeObj;
// email2 now contains the original as an attached message.
mailman.put_SmtpHost("smtp.comcast.net");
bool success = mailman.SendEmail(&email2);
if (!success)
{
mailman.SaveLastError("sendError.txt");
}
// Save our email to a .eml file so we can examine the MIME structure if desired.
email2.SaveEml("email2.eml");
}
Send Email via SMTP / SSL on Port 465
Download
Chilkat C/C++ Libraries for VC++ 9.0 / Win32Download Chilkat C/C++ Libraries for VC++ 8.0 / Win32
Download Chilkat C/C++ 64-bit Libraries for VC++ 8.0 / x64
Download Chilkat Visual Studio 2005 C/C++ Libs for Windows Mobile, Pocket PC, SmartPhone, WinCE
Download Chilkat C/C++ Libraries for VC++ 7.0 / Win32
Download Chilkat C/C++ Libraries for VC++ 6.0 / Win32
Download Chilkat C/C++ Libraries for VC++ 6.0, Win 95/98/NT4 Compatible
C++ Example showing how to make an SSL connection to an SMTP server and send email.
// Send email via an SSL connection with an SMTP server.
void SendEmailSsl(void)
{
CkMailMan mailman;
mailman.UnlockComponent("Anything for 30-day trial");
// Create a simple email for sending.
CkEmail email;
email.put_Body("This is a test");
email.put_Subject("Test email for SMTP SSL");
email.put_From("Chilkat Support ");
email.AddTo("Matt","matt@chilkatsoft.com");
// The SMTP SSL port is usually 465.
mailman.put_SmtpSsl(true);
mailman.put_SmtpPort(465);
// Set our SMTP hostname and login/password info.
// The login/password may or may not be necessary depending on your server
// and on the location from which you are connecting (i.e. depending on whether
// you may be inside or outside of a firewall, if one exists.)
mailman.put_SmtpHost("mail.chilkatsoft.com");
mailman.put_SmtpUsername("myLogin");
mailman.put_SmtpPassword("myPassword");
bool success = mailman.SendEmail(&email);
if (!success)
{
mailman.SaveLastError("sendError.txt");
}
return;
}
Using SMTP STARTTLS to Send Email over a Secure Channel
Download
Chilkat C/C++ Libraries for VC++ 9.0 / Win32Download Chilkat C/C++ Libraries for VC++ 8.0 / Win32
Download Chilkat C/C++ 64-bit Libraries for VC++ 8.0 / x64
Download Chilkat Visual Studio 2005 C/C++ Libs for Windows Mobile, Pocket PC, SmartPhone, WinCE
Download Chilkat C/C++ Libraries for VC++ 7.0 / Win32
Download Chilkat C/C++ Libraries for VC++ 6.0 / Win32
Download Chilkat C/C++ Libraries for VC++ 6.0, Win 95/98/NT4 Compatible
C++ Example showing how to use the SMTP STARTTLS option to send email over a secure channel.
// Send email over a secure connection using STARTTLS
void SendEmailStartTLS(void)
{
CkMailMan mailman;
mailman.UnlockComponent("Anything for 30-day trial");
// Create a simple email for sending.
CkEmail email;
email.put_Body("This is a test");
email.put_Subject("Test email for SMTP STARTTLS");
email.put_From("Chilkat Support ");
email.AddTo("Matt","matt@chilkatsoft.com");
// Connect on the normal SMTP port, but convert the connection to
// a TLS encrypted connection with STARTTLS. The SMTP authentication
// occurs over the encrypted channel.
mailman.put_StartTLS(true);
// Set our SMTP hostname and login/password info.
// The login/password may or may not be necessary depending on your server
// and on the location from which you are connecting (i.e. depending on whether
// you may be inside or outside of a firewall, if one exists.)
mailman.put_SmtpHost("mail.chilkatsoft.com");
mailman.put_SmtpUsername("myLogin");
mailman.put_SmtpPassword("myPassword");
bool success = mailman.SendEmail(&email);
if (!success)
{
mailman.SaveLastError("sendError.txt");
}
return;
}
Embed Image in HTML Email
Demonstrates how to create and send an HTML email with an
embedded image.Download Chilkat C++ Libraries for VC++ 8.0 / Win32
Download Chilkat C++ Libraries for VC++ 7.0 / Win32
Download Chilkat C++ Libraries for VC++ 6.0 / Win32
#include
#include
#include
void ChilkatSample(void)
{
// The mailman object is used for sending and receiving email.
CkMailMan mailman;
// Any string argument automatically begins the 30-day trial.
bool success;
success = mailman.UnlockComponent("30-day trial");
if (success != true) {
printf("Component unlock failed\n");
return;
}
// Set the SMTP server.
mailman.put_SmtpHost("smtp.comcast.net");
// Create a new email object
CkEmail email;
// Add an embedded image to the HTML email.
CkString fileOnDisk;
fileOnDisk = "images/dude2.gif";
CkString filePathInHtml;
filePathInHtml = "something/dudeAbc.gif";
// Embed the GIF image in the email.
success = email.AddRelatedFile2(fileOnDisk,filePathInHtml);
if (success != true) {
printf("%s\n",email.lastErrorText());
return;
}
// The src attribute for the image tag is set to the filePathInHtml:
CkString htmlBody;
htmlBody = "Embedded Image:
";
// Set the basic email stuff: HTML body, subject, "from", "to"
email.SetHtmlBody(htmlBody);
email.put_Subject("C++ HTML email with an embedded image.");
email.AddTo("Admin","admin@chilkatsoft.com");
email.put_From("Chilkat Support ");
success = mailman.SendEmail(email);
if (success != true) {
printf("%s\n",mailman.lastErrorText());
}
else {
printf("Mail Sent!\n");
}
}
Send a Simple Email
Create a simple email and sends it. The SendEmail method
establishes a connection (session) with the SMTP server if necessary, and
leaves the connection open so that additional sends may proceed using the same
session. The SMTP connection (session) may be explicitly closed by calling
CloseSmtpSession. Important: Some SMTP servers do not actually send the email until the connection is closed. In these cases, it is necessary to call CloseSmtpConnection for the mail to be sent. Most SMTP servers send the email immediately, and it is not required to close the connection.
More information about minimizing SMTP connections.
Download Chilkat C/C++ Libraries for VC++ 9.0 / Win32
Download Chilkat C/C++ Libraries for VC++ 8.0 / Win32
Download Chilkat C/C++ 64-bit Libraries for VC++ 8.0 / x64
Download Chilkat Visual Studio 2005 C/C++ Libs for Windows Mobile, Pocket PC, SmartPhone, WinCE
Download Chilkat C/C++ Libraries for VC++ 7.0 / Win32
Download Chilkat C/C++ Libraries for VC++ 6.0 / Win32
Download Chilkat C/C++ Libraries for VC++ 6.0, Win 95/98/NT4 Compatible
#include <CkMailMan.h>
#include <CkEmail.h>
void ChilkatSample(void)
{
// The mailman object is used for sending and receiving email.
CkMailMan mailman;
// Any string argument automatically begins the 30-day trial.
bool success;
success = mailman.UnlockComponent("30-day trial");
if (success != true) {
printf("Component unlock failed\n");
return;
}
// Set the SMTP server.
mailman.put_SmtpHost("smtp.chilkatsoft.com");
// Set the SMTP login/password (if required)
mailman.put_SmtpUsername("myUsername");
mailman.put_SmtpPassword("myPassword");
// Create a new email object
CkEmail email;
email.put_Subject("This is a test");
email.put_Body("This is a test");
email.put_From("Chilkat Support ");
email.AddTo("Chilkat Admin","admin@chilkatsoft.com");
// Call SendEmail to connect to the SMTP server and send.
// The connection (i.e. session) to the SMTP server remains
// open so that subsequent SendEmail calls may use the
// same connection.
success = mailman.SendEmail(email);
if (success != true) {
printf("%s\n",mailman.lastErrorText());
return;
}
// Some SMTP servers do not actually send the email until
// the connection is closed. In these cases, it is necessary to
// call CloseSmtpConnection for the mail to be sent.
// Most SMTP servers send the email immediately, and it is
// not required to close the connection. We'll close it here
// for the example:
success = mailman.CloseSmtpConnection();
if (success != true) {
printf("Connection to SMTP server not closed cleanly.\n");
}
printf("Mail Sent!\n");
}
댓글 없음:
댓글 쓰기
국정원의 댓글 공작을 지탄합니다.