C# Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CUnicode C++Unicode CMFCDelphi DLLDelphi ActiveXFoxProJavaPerlPHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

C# Examples

Bounced Mail
Bz2
Character Encoding
CSV
DKIM / DomainKey
Digital Certificates
Digital Signatures
Email
Email Object
FTP
HTML Conversion
HTTP
IMAP
Encryption
MHT / HTML Email
MIME
POP3
RSA
S/MIME
SMTP
Socket
Spider
SSH
SSH Tunnel
SSH Key
SFTP
Tar Archive
Upload
XML
XMP
Zip Compression


More Examples...
Amazon S3
NTLM
FileAccess
RSS
Atom
String
Byte Array
Self-Extractor
Service
PPMD
Deflate
DH Key Exchange
DSA
Bzip2
LZW

 

 

 

 

 

 

Email Distribution List with Mail Merge

Download: 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
must be downloaded and installed separately at http://www.chilkatsoft.com/downloads.asp.
Once installed, add a reference to the DLL in the project by following the instructions at
http://www.example-code.com/vbdotnet/step2.asp

 

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