Chilkat HOME Android™ ASP Visual Basic VB.NET C# iOS (IPhone) Objective-C C++ C Unicode C++ Unicode C MFC Delphi DLL Delphi ActiveX FoxPro Java Perl PHP Extension PHP ActiveX Python PowerShell Ruby SQL Server VBScript
Email Distribution List with Mail MergeDownload: Chilkat .NET Assemblies C# source code example showing how to send email using a distribution list with mail-merge. bool success = false; // Create a mailman object for sending email. Chilkat.MailMan mailman = new Chilkat.MailMan(); // Any string argument automatically begins the 30-day trial. mailman.UnlockComponent("30-day trial"); // Set the SMTP server. mailman.SmtpHost = "smtp.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. Chilkat.StringArray array = new Chilkat.StringArray(); array.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"); Chilkat.Email email = new Chilkat.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.Subject = "CUSTOMER_NAME: This is a test."; email.FromName = "Bob"; email.FromAddress = "bob@chilkatsoft.com"; int i; int numEmails = array.Count; string 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. friendlyName = email.GetToName(0); if (friendlyName.Length == 0) { friendlyName = friendlyName + "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); // 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: MessageBox.Show(mailman.LastErrorText); break; } } else { // Or... the mail can be sent in-process. if (!mailman.SendEmail(email)) { // We could send the email in-process: MessageBox.Show(mailman.LastErrorText); break; } } } Important: The download for this
example does not contain the ChilkatDotNet.dll which |
© 2000-2013 Chilkat Software, Inc. All Rights Reserved.