The ending characters that designate a mail merge field.
By default this value is set to ##. The following example sets MMSuffix to --$$.
[C#]
[STAThread]
static void Main(string[] args)
{
EmailMessage msg = new EmailMessage( "mail.myCompany.com");
msg.FromAddress = "me@myCompany.com";
msg.MMPrefix = "$$--";
msg.MMSuffix = "--$$";
msg.AddTo( "$$--fldEmail--$$" );
msg.Subject = "Hi $$--fldFirstName--$$";
//build a datagrid
DataGrid dg = new DataGrid();
//have a method called GetDataTAble() that builds a datatable from a database.
dg.DataSource = GetDataTable();
dg.DataBind();
msg.Body = "Hi $$--fldEmail--$$" + Environment.NewLine;
msg.Body += "Your invoice amount is $$--fldAmount--$$";
if ( msg.SendMailMerge( GetDataTable() ) )
{
Console.WriteLine("Messages Sent!");
}
else
{
Console.WriteLine("The following error occurred during the mail merge: " + msg.LastException().Message );
}
}
static DataTable GetDataTable()
{
OleDbConnection oConn;
OleDbDataAdapter oDa;
string sConn;
string sqlText;
DataSet oDataSet = new DataSet();
//Build the connection string
sConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=MailMerge.mdb;Persist Security Info=False";
//Build the SQL string
sqlText = "SELECT fldEmail, fldFirstName, fldDatePurchased, fldAmount FROM tblMembers";
//Usually you would use error-handling here. It is left out to make the code as simple as possible.
//Create the connection and command objects
oConn = new OleDbConnection(sConn);
oDa = new OleDbDataAdapter(sqlText, oConn);
//Fill the dataset with the results of the query
oDa.Fill(oDataSet, "tblMailMerge");
DataTable dtMailMerge = oDataSet.Tables[0];
return dtMailMerge;
}
[Visual Basic]
Sub Main()
Dim msg As New EmailMessage("mail.myCompany.com")
msg.FromAddress = "me@myCompany.com"
msg.MMPrefix = "$$--"
msg.MMSuffix = "--$$"
msg.AddTo("$$--fldEmail--$$")
msg.Subject = "Hi $$--fldFirstName--$$"
'build a datagrid
Dim dg As New DataGrid()
'have a method called GetDataTAble() that builds a datatable from a database.
dg.DataSource = GetDataTable()
dg.DataBind()
msg.Body = "Hi $$--fldEmail--$$" + Environment.NewLine
msg.Body += "Your invoice amount is $$--fldAmount--$$"
If msg.SendMailMerge(GetDataTable()) Then
Console.WriteLine("Messages Sent!")
Else
Console.WriteLine(("The following error occurred during the mail merge: " + msg.LastException().Message))
End If
End Sub
Private Function GetDataTable() As DataTable
Dim oConn As OleDbConnection
Dim oDa As OleDbDataAdapter
Dim sConn As String
Dim sqlText As String
Dim oDataSet As New DataSet()
'Build the connection string
sConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=MailMerge.mdb;Persist Security Info=False"
'Build the SQL string
sqlText = "SELECT fldEmail, fldFirstName, fldLastName, fldDatePurchased, fldAmount FROM tblMembers"
'Usually you would use error-handling here. It is left out to make the code as simple as possible.
'Create the connection and command objects
oConn = New OleDbConnection(sConn)
oDa = New OleDbDataAdapter(sqlText, oConn)
'Fill the dataset with the results of the query
oDa.Fill(oDataSet, "tblMailMerge")
Dim dtMailMerge As DataTable = oDataSet.Tables(0)
Return dtMailMerge
End Function