aspNetEmail

EmailMessage.SmtpServerResponse Event

The event for handling a response from the server.

public event SmtpServerResponseEventHandler SmtpServerResponse;

Event Data

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

PropertyDescription
ActualReplyCodeActual reply code sent from the SMTP server.
ExpectedReplyCodeThe reply code that was expected to come from the server.
ResponseThe last full response from the SMTP server.
SmtpStateThe state of the SMTP session
SocketThe underlying socket of the SMTP session.

Example

[C#]
            void SendEmail()
            {
            	EmailMessage msg = new EmailMessage( "mail.myCompany.com");
            	msg.FromAddress = "me@myCompany.com";
            	msg.To = "You@YourCompany.com";
            	msg.Subject = "test email";
            	msg.Body = "enter you body contents here...";
            
            	//logging for easier troubleshooting
            	msg.Logging = true;
            	msg.LogPath = "c:\\email.log";
            
            	//wire up the SmtpServerResponse event
            	msg.SmtpServerResponse += new SmtpServerResponseEventHandler( ServerResponse );
            
            	msg.Send(); 
            	
            }
            
            void ServerResponse( object sender, SmtpServerResponseEventArgs e )
            {
            	//here we can get access to the reply from the server
            
            	//what was expected
            	Console.WriteLine( e.ExpectedReplyCode );
            
            	//What was actually rec'd
            	Console.WriteLine( e.ActualReplyCode );
            	
            	//complete response
            	Console.WriteLine( e.Response );
            
            	//state of the SMTP session
            	Console.WriteLine( e.SmtpState.ToString() );
            }
            
            
            
            
[VB.NET]
            
            Sub SendEmail()
               Dim msg As New EmailMessage("mail.myCompany.com")
               msg.FromAddress = "me@myCompany.com"
               msg.To = "You@YourCompany.com"
               msg.Subject = "test email"
               msg.Body = "enter you body contents here..."
               
               'logging for easier troubleshooting
               msg.Logging = True
               msg.LogPath = "c:\email.log"
               
               'wire up the SmtpServerResponse event
               AddHandler msg.SmtpServerResponse, AddressOf ServerResponse
               
               msg.Send()
            End Sub 'SendEmail
             
            
            Sub ServerResponse(sender As Object, e As SmtpServerResponseEventArgs)
               'here we can get access to the reply from the server
               'what was expected
               Console.WriteLine(e.ExpectedReplyCode)
               
               'What was actually rec'd
               Console.WriteLine(e.ActualReplyCode)
               
               'complete response
               Console.WriteLine(e.Response)
               
               'state of the SMTP session
               Console.WriteLine(e.SmtpState.ToString())
            End Sub 'ServerResponse
            
            

See Also

EmailMessage Class | aspNetEmail Namespace