aspNetEmail

BeforeQueueWriteEventArgs Constructor (String, String[], Boolean)

Creats an instance of the BeforeQueueWrite Event Arguments.

public BeforeQueueWriteEventArgs(
   string directory,
   string[] filenames,
   bool doWrite
);

Parameters

directory
The directory to be used for writing emails.
filenames
Array of filename of the email.
doWrite
Write the email.

Remarks

The following example uses this table for sample data

emailaddressattachmentPathemailBody
bill@mycompany.comc:\temp\orders\bill.xlsplease review your order details
steve@hiscompany.comc:\temp\orders\steve.xlsplease review your order details
debbie@yourcompany.complease review your order details

Example

[C#]
            static void Main(string[] args)
            {
            	EmailMessage msg = new EmailMessage();
            	msg.Server = "mail.mycompany.com";
            	msg.FromAddress = "me@mycompany.com";
            	msg.To = "##emailaddress##";
            	msg.Subject = "see attached orders";
            	msg.Body = "##emailBody##";
                
            	msg.BeforeQueueWrite += new BeforeQueueWriteEventHandler( OnBeforeQueueWrite );
            
            	msg.MSPickupDirectory = "c:\\temp\\pickupDirectory\\";
            	msg.SendMailMergeToMSPickup( GetAttachmentTable() );
            
            
            }
            
            public static void OnBeforeQueueWrite( object sender, BeforeQueueWriteEventArgs e )
            {
            	//if we wanted to cancel the write we can call
            	//e.DoWrite = false;
            	
            	//write out the filename 
            	for( int i=0;i<e.Filenames.Length;i++)
            	{
            		Console.WriteLine( e.Filenames[ i ] );
            	}
            
            	//if we wanted to change the pickup directory, we can call
            	e.Directory = "c:\\temp\\pickupDirectory2\\";
            }
            
            public static DataTable GetAttachmentTable()
            {
            	string connectionString = "server=(local);database=northwind;trusted_connection=true;";
            	string sqlText = "SELECT emailaddress, emailBody FROM testEmailTable";
            	DataTable dt = new DataTable();
            	SqlDataAdapter da = new SqlDataAdapter( sqlText, connectionString );
            	da.Fill( dt );
            	return dt;
            }
            
[Visual Basic]
            Sub Main(ByVal args() As String)
            
                Dim msg As New EmailMessage()
                msg.Server = "mail.mycompany.com"
                msg.FromAddress = "me@mycompany.com"
                msg.To = "##emailaddress##"
                msg.Subject = "see attached orders"
                msg.Body = "##emailBody##"
            
                AddHandler msg.BeforeQueueWrite, AddressOf OnBeforeQueueWrite
            
                msg.MSPickupDirectory = "c:\temp\pickupDirectory\"
                msg.SendMailMergeToMSPickup(GetAttachmentTable())
            End Sub 'Main
            
            
            
            Public Sub OnBeforeQueueWrite(ByVal sender As Object, ByVal e As BeforeQueueWriteEventArgs)
                'if we wanted to cancel the write we can call
                'e.DoWrite = false;
                'write out the filename 
                Dim i As Integer
                For i = 0 To e.Filenames.Length - 1
                    Console.WriteLine(e.Filenames(i))
                Next i
            
                'if we wanted to change the pickup directory, we can call
                e.Directory = "c:\temp\pickupDirectory2\"
            End Sub 'OnBeforeQueueWrite
            
            
            Public Function GetAttachmentTable() As DataTable
                Dim connectionString As String = "server=(local);database=northwind;trusted_connection=true;"
                Dim sqlText As String = "SELECT emailaddress, emailBody FROM testEmailTable"
                Dim dt As New DataTable()
                Dim da As New SqlDataAdapter(sqlText, connectionString)
                da.Fill(dt)
                Return dt
            End Function 'GetAttachmentTable
            

See Also

BeforeQueueWriteEventArgs Class | aspNetEmail Namespace | BeforeQueueWriteEventArgs Constructor Overload List