Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
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 <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-2008 Chilkat Software, Inc. All Rights Reserved.