SmtpClient.Reset Method


Sends a RSET command to smtp server.

[Visual Basic]
Public Sub Reset( _
)
[C#]
public void Reset(
);
[C++]
public: void Reset(
);
[JScript]
public function Reset(
);

Remarks

The combination of Connect, Quit, Reset methods and SmtpClient.SendMail( SmtpMail mail ) methods sends multiple emails in one SMTP connection session. DO NOT use Connect, Quit and Reset methods with SmtpClient.SendMail( SmtpServer server, SmtpMail mail ) method. SmtpClient.SendMail( SmtpServer server, SmtpMail mail ) method connects and disconnects smtp server automatically.

Example

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

[VB - Send multiple emails in one SMTP connection session]
Imports EASendMail
Sub SendTwoMailsInOneConnection()
    Dim oMail As SmtpMail = New SmtpMail("TryIt")
    Dim oSmtp As SmtpClient = New SmtpClient

    Try
        Dim oServer As SmtpServer = New SmtpServer("myserveraddress")
        oSmtp.Connect( oServer )
        
        oMail.From = New MailAddress("from@adminsystem.com")
        oMail.To.Add(New MailAddress("to@adminsystem.com"))
        
        oMail.Subject = "firset test email"
        oMail.TextBody = "test body"
               
        oSmtp.SendMail( oMail )
        Console.WriteLine( "first sent" )
        oSmtp.Reset()
        oMail.Reset()
        
        oMail.From = New MailAddress("from@adminsystem.com")
        oMail.To.Add(New MailAddress("another@adminsystem.com"))    
        
        oMail.Subject = "second test email"
        oMail.TextBody = "another body"    
        
        oSmtp.SendMail( oMail )
        Console.WriteLine( "second sent" )
        oSmtp.Quit()  
    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

Sub SendMail()
    Dim oMail As SmtpMail = New SmtpMail("TryIt")
    Dim oSmtp As SmtpClient = New SmtpClient

    Try
        Dim oServer As SmtpServer = New SmtpServer("myserveraddress")
        
        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( oServer, oMail )
        Console.WriteLine( "message was sent" )
        
    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 multiple emails in one SMTP connection session]
using System;
using EASendMail;
void SendTwoMailsInOneConnection()
{
    SmtpMail oMail = new SmtpMail("TryIt");
    SmtpClient oSmtp = new SmtpClient();

    try
    {
        SmtpServer oServer = new SmtpServer("myserveraddress");
        oSmtp.Connect( oServer );
        
        oMail.From = new MailAddress("from@adminsystem.com" );
        oMail.To.Add( new MailAddress("to@adminsystem.com" ));
        oMail.Subject = "first test email";
        oMail.TextBody = "test body";
        
        oSmtp.SendMail( oMail );
        Console.WriteLine( "first sent" );
        oSmtp.Reset();
        oMail.Reset();

        oMail.From = new MailAddress("from@adminsystem.com" );
        oMail.To.Add( new MailAddress("another@adminsystem.com" ));
        oMail.Subject = "second test email";
        oMail.TextBody = "another body";
        
        oSmtp.SendMail( oMail );
        Console.WriteLine( "second sent" );
        oSmtp.Quit();
    }
    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 );
}

void SendMail()
{
    SmtpMail oMail = new SmtpMail("TryIt");
    SmtpClient oSmtp = new SmtpClient();

    try
    {
        SmtpServer oServer = new SmtpServer("myserveraddress");
        
        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( oServer, oMail );
		Console.WriteLine( "message was sent" );
    }
    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 multiple emails in one SMTP connection session]
using namespace System;
using namespace EASendMail;

void SendTwoMailsInOneConnection()
{
    SmtpMail ^oMail = gcnew SmtpMail("TryIt");
    SmtpClient ^oSmtp = gcnew SmtpClient();

    try
    {
        SmtpServer ^oServer = gcnew SmtpServer("myserveraddres");
        oSmtp->Connect( oServer );
            
        oMail->From = gcnew MailAddress("from@adminsystem.com" );
        oMail->To->Add( gcnew MailAddress("to@adminsystem.com" ));
        oMail->Subject = "first test email";
        oMail->TextBody = "test body";
        
        oSmtp->SendMail( oMail );
        Console::WriteLine( "first sent" );
        
        oSmtp->Reset();
        oMail->Reset();
        
        oMail->From = gcnew MailAddress("from@adminsystem.com" );
        oMail->To->Add( gcnew MailAddress("another@adminsystem.com" ));
        oMail->Subject = "second test email";
        oMail->TextBody = "another body";        
        
        oSmtp->SendMail( oMail );  
        Console::WriteLine( "second sent" );
        oSmtp->Quit();  
    }
    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 );
}

void SendMail()
{
    SmtpMail ^oMail = gcnew SmtpMail("TryIt");
    SmtpClient ^oSmtp = gcnew SmtpClient();

    try
    {
        SmtpServer ^oServer = gcnew SmtpServer("myserveraddres");
            
        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( oServer, oMail );
        Console::WriteLine( "message was sent" );
    }
    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

SmtpClient.SendMail Method
SmtpClient.Quit Method
SmtpClient.Connect Method