SmtpConnectType Enumeration


Specifies the connection type to smtp server.

[Visual Basic]
Public Enum SmtpConnectType
[C#]
public enum SmtpConnectType
[C++]
__value public enum SmtpConnectType
[JScript]
public enum SmtpConnectType

Members

Members name Description
ConnectNormal Specifies that the smtp server uses normal TCP/IP connection.
ConnectSSLAuto Specifies that the smtp client selects the STARTTLS/Direct SSL automatically.
ConnectSTARTTLS Specifies that the smtp server deploys SSL connection by STARTTLS command.
ConnectDirectSSL Specifies that the smtp server deploys SSL connection directly.
ConnectTryTLS If smtp server supports TLS, then TLS connection is used; otherwise, normal TCP connection is used.

Example

[Visual Basic, C#, C++] The following example demonstrates how to send email with SmtpClient class. To get the full samples of EASendMail, please refer to Samples section.

[VB - Send Email using SMTP Server over SSL/TLS]
Imports EASendMail
Sub SendMail()
    Dim oMail As SmtpMail = New SmtpMail("TryIt")
    Dim oSmtp As SmtpClient = New SmtpClient

    Try
        Dim oServer As SmtpServer = New SmtpServer("smtp.adminsystem.com")
        
        'set user authentication
        oServer.UserName = "myuser@adminsystem.com"
        oServer.Password = "mypassword"
        
        'specifies the authentication mechanism.
        oSmtp.AuthType = SmtpAuthType.AuthAuto
        
        'set SSL connection
        oServer.ConnectType = SmtpConnectType.ConnectSSLAuto
        
        'set smtp server port
        'oServer.Port = 465
        
        'set helo domain
        'oServer.HeloDomain = "mymachine.com"
        
        
        oMail.From = New MailAddress("from@adminsystem.com")
        oMail.To.Add(New MailAddress("to@adminsystem.com"))
        
        oMail.Subject = "test email sent from VB"
        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

End Sub

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

    try
    {
        SmtpServer oServer = new SmtpServer("smtp.adminsystem.com");
        
        //set user authentication
        oServer.UserName = "myuser@adminsystem.com";
        oServer.Password = "mypassword";
        
        //specifies the authentication mechanism.
        oSmtp.AuthType = SmtpAuthType.AuthAuto;
        
        //set SSL connection
        oServer.ConnectType = SmtpConnectType.ConnectSSLAuto;
        
        //set smtp server port
        //oServer.Port = 465;
        
        //set helo domain
        //oServer.HeloDomain = "mymachine.com";
        
                
        oMail.From = new MailAddress("from@adminsystem.com" );
        oMail.To.Add( new MailAddress("to@adminsystem.com" ));
        oMail.Subject = "test email sent from C#";
        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 );         
    }
}
        
[C++/CLI - Send Email using SMTP Server over SSL/TLS]
using namespace System;
using namespace EASendMail;
void SendMail()
{
    SmtpMail ^oMail = gcnew SmtpMail("TryIt");
    SmtpClient ^oSmtp = gcnew SmtpClient();

    try
    {
        SmtpServer ^oServer = gcnew SmtpServer("smtp.adminsystem.com");
		
        //set user authentication
        oServer->UserName = "myuser@adminsystem.com";
        oServer->Password = "mypassword";
        
        //specifies the authentication mechanism.
        oSmtp->AuthType = SmtpAuthType::AuthAuto;
        
        //set SSL connection
        oServer->ConnectType = SmtpConnectType::ConnectSSLAuto;
        
        //set smtp server port
        //oServer->Port = 465;
        
        //set helo domain
        //oServer->HeloDomain = "mymachine.com";
                    
        oMail->From = gcnew MailAddress("from@adminsystem.com" );
        oMail->To->Add( gcnew MailAddress("to@adminsystem.com" ));
        oMail->Subject = "test email sent from C++/CLI";
        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 );           
    }
}

See Also

User Authentication and SSL Connection
From, ReplyTo, Sender and Return-Path
Process Bounced Email (Non-Delivery Report) and Email Tracking

Online Tutorial

Send Email over SSL/TLS in C#
Send Email using Gmail in C#
Send Email using Yahoo in C#
Send Email using Hotmail/Live in C#

Send Email over SSL/TLS in VB
Send Email using Gmail in VB
Send Email using Yahoo in VB
Send Email using Hotmail/Live in VB

Send Email over SSL/TLS in C++/CLI
Send Email using Gmail in C++/CLI
Send Email using Yahoo in C++/CLI
Send Email using Hotmail/Live in C++/CLI