SmtpClient.CurrentSmtpServer Property


Gets the latest smtp server that is used to send e-mail message.

[Visual Basic]
Public Property CurrentSmtpServer As SmtpServer
[C#]
public SmtpServer CurrentSmtpServer {get;}
[C++]
public: __property SmtpServer^ get_CurrentSmtpServer();
[JScript]
public function get CurrentSmtpServer() : SmtpServer;

Property Value

The latest SmtpServer class instance that sends e-mail message.

Remarks

This property is meaningless for sending email with specified smtp server, because the smtp server address is known. However, if the client sends e-mail without specified smtp server, the property indicates the latest smtp server that sent the email message.

Example

[Visual Basic, C#, C++] To get the full samples of EASendMail, please refer to Samples section.

[VB - Send Email]
Imports EASendMail
Sub SendMail()
    Dim oMail As SmtpMail = New SmtpMail("TryIt")
    Dim oSmtp As SmtpClient = New SmtpClient

    Try
        oMail.From = New MailAddress("from@adminsystem.com")
        oMail.To.Add(New MailAddress("to@adminsystem.com"))
        oMail.Subject = "test subject"
        oMail.TextBody = "test body"
        oSmtp.SendMail(Nothing, oMail)
        Console.WriteLine("the message was sent to {0} successfully", _
    oSmtp.CurrentSmtpServer.Server)
    Catch exp As SmtpTerminatedException
        Console.WriteLine(exp.Message)
    Catch exp As SmtpServerException
        Console.WriteLine("Exception: Server Respond: {0}", exp.ErrorMessage)
    Catch exp As System.Net.Sockets.SocketException
        Console.WriteLine("Exception: Networking Error: {0} {1}", exp.ErrorCode, exp.Message)
    Catch exp As System.ComponentModel.Win32Exception
        Console.WriteLine("Exception: System Error: {0} {1}", exp.ErrorCode, exp.Message)
    Catch exp As System.Exception
        Console.WriteLine("Exception: Common: {0}", exp.Message)
    End Try

    Console.WriteLine("SMTP LOG:" & vbCrLf)
    Console.WriteLine(oSmtp.SmtpConversation)
End Sub

[C# - Send Email]
using System;
using EASendMail;
void SendMail()
{
    SmtpMail oMail = new SmtpMail("TryIt");
    SmtpClient oSmtp = new SmtpClient();

    try
    {
        oMail.From = new MailAddress("from@adminsystem.com" );
        oMail.To.Add( new MailAddress("to@adminsystem.com" ));
        oMail.Subject = "test subject";
        oMail.TextBody = "test body";
        oSmtp.SendMail( null, oMail );
        Console.WriteLine( "the message was sent to {0} successfully",
            oSmtp.CurrentSmtpServer.Server );
    }
    catch( SmtpTerminatedException exp )
    {
        Console.WriteLine( exp.Message );
    }
    catch( SmtpServerException exp )
    {
        Console.WriteLine( "Exception: Server Respond: {0}", exp.ErrorMessage );
    }
    catch( System.Net.Sockets.SocketException exp )
    {
        Console.WriteLine( "Exception: Networking Error: {0} {1}", exp.ErrorCode, exp.Message );
    }
    catch( System.ComponentModel.Win32Exception exp )
    {
        Console.WriteLine( "Exception: System Error: {0} {1}", exp.ErrorCode, exp.Message );            
    }
    catch( System.Exception exp )
    {
        Console.WriteLine( "Exception: Common: {0}", exp.Message );         
    }

    Console.WriteLine( "SMTP LOG:\r\n" );
    Console.WriteLine( oSmtp.SmtpConversation );
}

[C++/CLI - Send Email]
using namespace System;
using namespace EASendMail;
void SendMail()
{
    SmtpMail ^oMail = gcnew SmtpMail("TryIt");
    SmtpClient ^oSmtp = gcnew SmtpClient();

    try
    {
        oMail->From = gcnew MailAddress("from@adminsystem.com" );
        oMail->To->Add( gcnew MailAddress("to@adminsystem.com" ));
        oMail->Subject = "test subject";
        oMail->TextBody = "test body";
        oSmtp->SendMail( NULL, oMail );
        Console::WriteLine( "the message was sent to {0} successfully",
            oSmtp->CurrentSmtpServer->Server );
    
    }
    catch( EASendMail::SmtpTerminatedException ^exp )
    {
        Console::WriteLine( exp->Message );
    }
    catch( EASendMail::SmtpServerException ^exp )
    {
        Console::WriteLine( "Exception: Server Respond: {0}", exp->ErrorMessage );
    }
    catch( System::Net::Sockets::SocketException ^exp )
    {
        Console::WriteLine( "Exception: Networking Error: {0} {1}", exp->ErrorCode.ToString("d"), exp->Message );
    }
    catch( System::ComponentModel::Win32Exception ^exp )
    {
        Console::WriteLine( "Exception: System Error: {0} {1}", exp->ErrorCode.ToString("d"), exp->Message );         
    }
    catch( System::Exception ^exp )
    {
        Console::WriteLine( "Exception: Common: {0}", exp->Message );          
    }

    Console::WriteLine( "SMTP LOG:\r\n" );
    Console::WriteLine( oSmtp->SmtpConversation );
}

See Also

Send E-mail Directly (Simulating SMTP server)