aspNetEmail

EmailMessage.BeforeQueueWrite Event

A BeforeQueueWrite event has occurred.

public event BeforeQueueWriteEventHandler BeforeQueueWrite;

Event Data

The event handler receives an argument of type BeforeQueueWriteEventArgs containing data related to this event. The following BeforeQueueWriteEventArgs properties provide information specific to this event.

PropertyDescription
Directory The directory emails are written too.
DoWrite If True, the email will be written to the queue directory. If False, the email will not be written.
Filenames The Filename that will be used to name the email.
Row MailMerge Row Data

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( GetDataTable() );
	 
	 
	 }
	 
	 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 GetDataTable()
	 {
	 	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(GetDataTable())
	 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 GetDataTable() 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

EmailMessage Class | aspNetEmail Namespace