A datatable that contains data to use with the MailMerge or Send methods.
A datatable
If you specify a value for this property, that is not null, and a call to the Send method is made, the component will attempt to address the message using that data. If a value is specified for this property and the method MailMerge is called, it's value will be overwritten because the MailMerge method expects a DataSet as one of its parameters.
[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.ToAddress = "to@domain.com";
oSmtpDotNet.FromAddress = "from@domain.com";
// Set the DBDataTable to an object that is of type DataTable
oSmtpDotNet.DBDataTable = myDataTable;
// Set other DB properties
oSmtpDotNet.DBRecipientType = AddressTypes.TO;
oSmtpDotNet.DBEmailColumn = "email";
oSmtpDotNet.DBFriendlyColumn = "customerFirstName,customerLastName";
// Set the message subject and body
oSmtpDotNet.Body = "This is the message";
oSmtpDotNet.Subject = "Routine email";
ReturnCodes nRC = oSmtpDotNet.Send();
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"
oSmtpDotNet.ToAddress = "to@domain.com"
' Set the DBDataTable to an object that is of type DataTable
oSmtpDotNet.DBDataTable = myDataTable
oSmtpDotNet.DBRecipientType = AddressTypes.TO
' Set other DB properties
oSmtpDotNet.DBEmailColumn = "email"
oSmtpDotNet.DBFriendlyColumn = "customerFirstName,customerLastName"
' Set the message subject and body
oSmtpDotNet.Subject = "Routine email"
oSmtpDotNet.Body = "This is a briefing of the financials"
' Send the message. Get the return code and store it in the variable
' nRC. Then check nRC for success or failure
nRC = oSmtpDotNet.Send()
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 | DataTable | DBEmailColumn | DBFriendlyColumn | DBRecipientLimit | DBRecipientType