Combines data from the DBDataTable with various properties in the message.
[Visual Basic]
Public Function MailMerge( _
ByVal dataTable As DataTable, _
ByVal emailColumn As String, _
ByVal recipientType As AddressTypes, _
ByVal replacementIds As Hashtable _
) As ReturnCodes
An integer of enumerated type ReturnCodes.
After this method is called, all recipients in the "to", "cc", "bcc" fields are cleared.
For example: In the message, "Dear $A$: Thank you for ordering $B$ from our $C$ store...", $A$, $B$ and $C$ are merge points into which data is inserted from the list.
Letter | Database | ||
Dear $A$: Thank you for ordering $B$ at our $C$ store. Sincerely, The store owners | $A$ | $B$ | $C$ |
Mr. Smith | 1 Widget | New York | |
Ms. Gomer | 2 Dingits | Chicago | |
Mr. Jones | 1 Frabbits | Los Angeles | |
Mr. Silver | 3 Widgets | Tucson | |
Ms. Change | 2 Gobbits | Philadelphia | |
Mr. Russion | 5 Wibbles | Washington D.C | |
Example Output (without formatting):
Dear Mr. Smith: Thank you for ordering 1 Widget at our New York store. Sincerely, The store owners
Dear Ms. Gomer: Thank you for ordering 2 Dingits at our Chicago store. Sincerely, The store owners
Dear Mr. Jones: Thank you for ordering 1 Frabbits at our Los Angeles store. Sincerely, The store owners
Dear Mr. Silver: Thank you for ordering 3 Widgets at our Tucson store. Sincerely, The store owners
Dear Ms. Change: Thank you for ordering 2 Gobbits at our Philadelphia store. Sincerely, The store owners
Dear Mr. Russion: Thank you for ordering 3 Wibbles at our Washington D.C. store. Sincerely, The store owners
[C#]
public void Send()
{
SmtpServer oSmtpDotNet = new SmtpServer();
// Set the remote server name. If left blank, "localhost" is used.
oSmtpDotNet.ServerAddress = "mail.domain.com"
// Message Addressing
oSmtpDotNet.FromAddress = "from@domain.com";
// Set the message subject and body
oSmtpDotNet.Body = "Dear $A$: Thank you for ordering $B$ at our $C$ store. Sincerely, The store owners";
oSmtpDotNet.Subject = "Your order of $B$";
// Set up the hashtable for the mail merge replacements.
Hashtable oHashtable = new Hashtable();
oHashtable.Add("$A$", "customerSalutation,customerLastName");
oHashtable.Add("$B$", "itemCount,itemName");
oHashtable.Add("$C$", "itemStoreSoldName");
ReturnCodes nRC = oSmtpDotNet.MailMerge(dataTable, "customerEmail", SmtpDotNet.AddressTypes.TO, oHashtable);
if ( nRC != ReturnCodes.SUCCESS )
{
Console.WriteLine("Error #"+nRC+" occurred.");
Console.WriteLine(oSmtpDotNet.LastError);
Console.Write(oSmtpDotNet.LogFileToString(false));
return;
}
// Success!
Console.WriteLine("Success!");
}
[VB]
Public Function Send() As Integer
Dim oSmtpDotNet As New SmtpServer()
Dim nRC As ReturnCodes
' Set the remote server name. If left blank, "localhost" is used.
oSmtpDotNet.ServerAddress = "mail.domain.com"
' Message Addressing
oSmtpDotNet.FromAddress = "from@domain.com"
' Set the message subject and body
oSmtpDotNet.Body = "Dear $A$: Thank you for ordering $B$ at our $C$ store. Sincerely, The store owners"
oSmtpDotNet.Subject = "Your order of $B$"
' Set up the hashtable for the mail merge replacements.
Hashtable oHashtable = new Hashtable()
oHashtable.Add("$A$", "customerSalutation,customerLastName")
oHashtable.Add("$B$", "itemCount,itemName")
oHashtable.Add("$C$", "itemStoreSoldName")
ReturnCodes nRC = oSmtpDotNet.MailMerge(dataTable, "customerEmail", SmtpDotNet.AddressTypes.TO, oHashtable)
If (nRC <> ReturnCodes.SUCCESS) Then
' A problem occurred.
' Write out the last error encountered
Console.WriteLine(oSmtpDotNet.LastError)
' Write out the log file contents
Console.WriteLine(oSmtpDotNet.LogFileToString(False))
Exit Function
End If
' Success!
Console.WriteLine("Message Sent!")
End Function
SmtpServer Class | SmtpServer Members | SmtpDotNet Namespace | ReturnCodes