aspNetEmail

EmailMessage.BeforeEmailSend Event

A BeforeEmailSend event has occurred.

public event BeforeEmailSendEventHandler BeforeEmailSend;

Event Data

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

PropertyDescription
EmailContents The complete email contents, about to be sent to the mail server.
Send If false, the email is not sent

Example

[C#]
            static void Main(string[] args)
            {
            
            	EmailMessage msg = new EmailMessage();
            
            	//wire up the before send event, to check the mail contents
            	msg.BeforeEmailSend += new BeforeEmailSendEventHandler( OnBeforeEmailSend );
            
            	//load settings from the web.config
            	msg.LoadFromConfig();  
            
            	msg.Body = "this is my test body.";
            	msg.Send();
            
            
            	Console.WriteLine( "done" );			
            	Console.ReadLine();	
            
            }
            
            private static void OnBeforeEmailSend( object sender, BeforeEmailSendEventArgs e )
            {
            	//in here we can check the rendered email contents
            	Console.WriteLine( e.EmailContents );
            
            	//if we do not want to send the email, uncomment the following line
            	//e.Send = false;
            
            }
            
            
[Visual Basic]
            Public Overloads Sub Main()
               
               Dim msg As New EmailMessage()
               
               'wire up the before send event, to check the mail contents
               AddHandler msg.BeforeEmailSend, AddressOf OnBeforeEmailSend
               
               'load settings from the web.config
               msg.LoadFromConfig()
               
               msg.Body = "this is my test body."
               msg.Send()
               
               
               Console.WriteLine("done")
               Console.ReadLine()
            End Sub 'Main
             
            
            Private Sub OnBeforeEmailSend(sender As Object, e As BeforeEmailSendEventArgs)
               'in here we can check the rendered email contents
               Console.WriteLine(e.EmailContents)
               
            'if we do not want to send the email, uncomment the following line
            'e.Send = false;
            
            End Sub 'OnBeforeEmailSend 
            
            

See Also

EmailMessage Class | aspNetEmail Namespace