Disconnects the smtp server.
[Visual Basic] Public Sub Quit( _ )
[C#] public void Quit( );
[C++] public: void Quit( );
[JScript] public function Quit( );
Remarks
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()
Try
Dim oServer As SmtpServer = New SmtpServer("myserveraddress")
' SMTP user authentication
oServer.User = "myusername"
oServer.Password = "mypassword"
' Most mordern SMTP servers require SSL/TLS connection now.
' ConnectTryTLS means if server supports SSL/TLS, SSL/TLS will be used automatically.
oServer.ConnectType = SmtpConnectType.ConnectTryTLS
Dim oSmtp As SmtpClient = New SmtpClient
oSmtp.Connect(oServer)
Dim oMail As SmtpMail = New SmtpMail("TryIt")
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 Exception
Console.WriteLine("Exception: {0}", exp.Message)
End Try
End Sub
Sub SendMail()
Try
Dim oServer As SmtpServer = New SmtpServer("myserveraddress")
' SMTP user authentication
oServer.User = "myusername"
oServer.Password = "mypassword"
' Most mordern SMTP servers require SSL/TLS connection now.
' ConnectTryTLS means if server supports SSL/TLS, SSL/TLS will be used automatically.
oServer.ConnectType = SmtpConnectType.ConnectTryTLS
Dim oMail As SmtpMail = New SmtpMail("TryIt")
oMail.From = New MailAddress("from@adminsystem.com")
oMail.To.Add(New MailAddress("to@adminsystem.com"))
oMail.Subject = "test subject"
oMail.TextBody = "test body"
Dim oSmtp As SmtpClient = New SmtpClient()
oSmtp.SendMail(oServer, oMail)
Console.WriteLine("message was sent")
Catch exp As Exception
Console.WriteLine("Exception: {0}", exp.Message)
End Try
End Sub
[C# - Send multiple emails in one SMTP connection session]
using System;
using EASendMail;
void SendTwoMailsInOneConnection()
{
try
{
SmtpServer oServer = new SmtpServer("myserveraddress");
// SMTP user authentication
oServer.User = "myusername";
oServer.Password = "mypassword";
// Most mordern SMTP servers require SSL/TLS connection now.
// ConnectTryTLS means if server supports SSL/TLS, SSL/TLS will be used automatically.
oServer.ConnectType = SmtpConnectType.ConnectTryTLS;
SmtpClient oSmtp = new SmtpClient();
oSmtp.Connect(oServer);
SmtpMail oMail = new SmtpMail("TryIt");
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 (Exception exp)
{
Console.WriteLine("Exception: {0}", exp.Message);
}
}
void SendMail()
{
try
{
SmtpServer oServer = new SmtpServer("myserveraddress");
// SMTP user authentication
oServer.User = "myusername";
oServer.Password = "mypassword";
// Most mordern SMTP servers require SSL/TLS connection now.
// ConnectTryTLS means if server supports SSL/TLS, SSL/TLS will be used automatically.
oServer.ConnectType = SmtpConnectType.ConnectTryTLS;
SmtpMail oMail = new SmtpMail("TryIt");
oMail.From = new MailAddress("from@adminsystem.com");
oMail.To.Add(new MailAddress("to@adminsystem.com"));
oMail.Subject = "test subject";
oMail.TextBody = "test body";
SmtpClient oSmtp = new SmtpClient();
oSmtp.SendMail(oServer, oMail);
Console.WriteLine("message was sent");
}
catch (Exception exp)
{
Console.WriteLine("Exception: {0}", exp.Message);
}
}
[C++/CLI - Send multiple emails in one SMTP connection session]
using namespace System;
using namespace EASendMail;
void SendTwoMailsInOneConnection()
{
try
{
SmtpServer ^oServer = gcnew SmtpServer("myserveraddres");
// SMTP user authentication
oServer->User = "myusername";
oServer->Password = "mypassword";
// Most mordern SMTP servers require SSL/TLS connection now.
// ConnectTryTLS means if server supports SSL/TLS, SSL/TLS will be used automatically.
oServer->ConnectType = SmtpConnectType::ConnectTryTLS;
SmtpClient ^oSmtp = gcnew SmtpClient();
oSmtp->Connect(oServer);
SmtpMail ^oMail = gcnew SmtpMail("TryIt");
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 (Exception ^exp)
{
Console::WriteLine("Exception: {0}", exp->Message);
}
}
void SendMail()
{
try
{
SmtpServer ^oServer = gcnew SmtpServer("myserveraddres");
// SMTP user authentication
oServer->User = "myusername";
oServer->Password = "mypassword";
// Most mordern SMTP servers require SSL/TLS connection now.
// ConnectTryTLS means if server supports SSL/TLS, SSL/TLS will be used automatically.
oServer->ConnectType = SmtpConnectType::ConnectTryTLS;
SmtpMail ^oMail = gcnew SmtpMail("TryIt");
oMail->From = gcnew MailAddress("from@adminsystem.com");
oMail->To->Add(gcnew MailAddress("to@adminsystem.com"));
oMail->Subject = "test subject";
oMail->TextBody = "test body";
SmtpClient ^oSmtp = gcnew SmtpClient();
oSmtp->SendMail(oServer, oMail);
Console::WriteLine("message was sent");
}
catch (Exception ^exp)
{
Console::WriteLine("Exception: {0}", exp->Message);
}
}
See Also
SmtpClient.SendMail Method
SmtpClient.Connect Method
SmtpClient.Reset Method