Visual C++ Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

Visual C++ Examples

CkString
Byte Array
Bounced Mail
Bz2
Character Encoding
CSV
DH Key Exchange
DKIM/DomainKeys
Digital Certificates
Digital Signatures
DSA
Email
Encryption
FTP
HTML-to-XML
HTTP
IMAP
MHT / HTML Email
POP3
RSA
S/MIME
SMTP
Socket
Spider
SSH Key
SSH
SSH Tunnel
SFTP
Tar
Upload
XML
XMP
Zip Compression


More Examples...
Email Object
NTLM
FileAccess
RSS
Atom
Self-Extractor
Service
PPMD
Deflate
Bzip2
LZW

 

 

 

 

 

 

 

 

Send Email to Distribution List using Mail Merge

Download Chilkat C/C++ Libraries for VC++ 9.0 / Win32

Download Chilkat C/C++ Libraries for VC++ 9.0 / x64

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

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 <support@chilkatsoft.com>");
    array.Append("\"Chilkat Sales\" <sales@chilkatsoft.com>");
    array.Append("<matt@chilkatsoft.com>");
    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("<html><body>Hello CUSTOMER_NAME<br>This is a test</body></html>");

    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<numEmails; 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;
		}
	    }

	}


    }

 

 

 

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2010 Chilkat Software, Inc. All Rights Reserved.

Mail Component · .NET Mail Component · XML Parser