The text about to be sent to the Smtp server.
If you are re-writing a Smtp command, be sure it is properly terminated with CrLf (\r\n), or else the server will timeout or reject the command.
[C#]
void SendEmail()
{
EmailMessage.LoadLicenseFile( "c:\\aspnetemail.xml.lic" );
//load the values from the .config file. see the help for more information on this .ctor
EmailMessage m = new EmailMessage( true, false );
m.Subject="a test email to test the BeforeSmtpServer event";
m.Body = "test test";
m.To = "dave@aspnetemail.com";
m.LogPath = "c:\\email.log";
m.LogOverwrite = true;
m.Logging = true;
m.BeforeSmtpSend += new BeforeSmtpSendEventHandler( OnBeforeSmtpServerSend );
m.Send();
Console.WriteLine( "done...");
Console.ReadLine();
}
private void OnBeforeSmtpServerSend( object sender, BeforeSmtpSendEventArgs e )
{
Console.WriteLine( e.Text );
Console.WriteLine( e.SmtpState );
//here we could do some checking, and over ride the data sent to the server
if( e.SmtpState == SmtpState.MailFrom )
{
//here we could change the mail from info
e.Text = "Mail From:<test@test.com>\r\n";
}
//if we wanted to cancel sending this command we set
//e.Cancel = true;
//this will not close the socket connection, but simply not send the value of e.Text
//if we want to write directly to the socket, we have access to the underlying socket
//e.Socket.Send(....)
}
[Visual Basic]
Sub SendEmail()
EmailMessage.LoadLicenseFile("c:\aspnetemail.xml.lic")
'load the values from the .config file. see the help for more information on this .ctor
Dim m As New EmailMessage(True, False)
m.Subject = "a test email to test the BeforeSmtpServer event"
m.Body = "test test"
m.To = "dave@aspnetemail.com"
m.LogPath = "c:\email.log"
m.LogOverwrite = True
m.Logging = True
AddHandler m.BeforeSmtpSend, AddressOf OnBeforeSmtpServerSend
m.Send()
Console.WriteLine("done...")
Console.ReadLine()
End Sub 'SendEmail
Private Sub OnBeforeSmtpServerSend(sender As Object, e As BeforeSmtpSendEventArgs)
Console.WriteLine(e.Text)
Console.WriteLine(e.SmtpState)
'here we could do some checking, and over ride the data sent to the server
If e.SmtpState = SmtpState.MailFrom Then
'here we could change the mail from info
e.Text = "Mail From:<test@test.com>" + ControlChars.Cr + ControlChars.Lf
End If
End Sub 'OnBeforeSmtpServerSend
'if we wanted to cancel sending this command we set
'e.Cancel = true;
'this will not close the socket connection, but simply not send the value of e.Text
'if we want to write directly to the socket, we have access to the underlying socket
'e.Socket.Send(....)
End Sub 'Server_OnResponse