A BeforeEmailSend event has occurred.
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.
| Property | Description |
|---|---|
| EmailContents | The complete email contents, about to be sent to the mail server. |
| Send | If false, the email is not sent |
[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