The event for handling a response from the server.
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.
| Property | Description |
|---|---|
| ActualReplyCode | Actual reply code sent from the SMTP server. |
| ExpectedReplyCode | The reply code that was expected to come from the server. |
| Response | The last full response from the SMTP server. |
| SmtpState | The state of the SMTP session |
| Socket | The underlying socket of the SMTP session. |
[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