ServerProtocol Enumeration


Specifies the protocol (SMTP/Exchange Web Service/Exchange WebDAV) for mail server.

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

Members

Members name Description
SMTP Specifies that the mail server uses standard SMTP protocol.
ExchangeEWS Specifies that that the mail server uses Exchange Web Service protocol. Exchange 2007 or later version supports this protocol.
ExchangeWebDav Specifies that that the mail server uses Exchange Web Dav protocol. Exchange 2000/2003 supports this protocol.

Remarks

Standard SMTP protocol is always recommended.

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.

Example

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

[Visual Basic - Send Email using Stanard SMTP Protocol]

Imports EASendMail

Sub SendMail_SMTP()

    Try
        Dim oServer As SmtpServer = New SmtpServer("smtp.adminsystem.com")
        ' set user authentication
        oServer.User = "myuser@adminsystem.com"
        oServer.Password = "mypassword"

        ' specifies the authentication mechanism, AuthAuto is default value
        ' oSmtp.AuthType = SmtpAuthType.AuthAuto

        ' 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

        ' set SSL/TLS connection
        ' oServer.ConnectType = SmtpConnectType.ConnectSSLAuto

        ' set SMTP server port to 587, default value is 25
        ' oServer.Port = 587

        ' set SMTP server port to 465, 
        ' if 465 port is used, ConnectType should use ConnectSSLAuto or ConnectDirectSSL.
        ' oServer.Port = 465

        ' set helo domain, default value is current machine name
        ' oServer.HeloDomain = "mymachine.com"

        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 email sent from VB"
        oMail.TextBody = "test body"
                        
        Dim oSmtp As SmtpClient = New SmtpClient()
        oSmtp.SendMail(oServer, oMail)
        Console.WriteLine("This email has been submitted to server successfully!")

    Catch exp As Exception
        Console.WriteLine("Exception: {0}", exp.Message)
    End Try

End Sub


[Visual Basic - Send Email using Exchange Web Service - EWS] Imports EASendMail Sub SendMail_Exchange_EWS() Try ' Your Exchange server address Dim oServer As SmtpServer = New SmtpServer("exch.adminsystem.com") ' Set Exchange Web Service protocol (EWS) - Exchange 2007/2010/2013/2016/2019/Office 365 oServer.Protocol = ServerProtocol.ExchangeEWS ' User and password for Exchange User authentication oServer.User = "myuser@adminsystem.com" oServer.Password = "mypassword" ' By default, Exchange Web Service requires SSL connection oServer.ConnectType = SmtpConnectType.ConnectSSLAuto Dim oMail As SmtpMail = New SmtpMail("TryIt") oMail.From = New MailAddress("myuser@adminsystem.com") oMail.To.Add(New MailAddress("to@adminsystem.com")) oMail.Subject = "test email sent from VB with EWS protocol" oMail.TextBody = "test body" Dim oSmtp As SmtpClient = New SmtpClient() oSmtp.SendMail(oServer, oMail) Console.WriteLine("This email has been submitted to server successfully!") Catch exp As Exception Console.WriteLine("Exception: {0}", exp.Message) End Try End Sub
[Visual Basic - Send Email using Exchange WebDAV] Imports EASendMail Sub SendMail_Exchange_WebDav() Try ' Your Exchange server address Dim oServer As SmtpServer = New SmtpServer("exch.adminsystem.com") ' Set Exchange WebDAV protocol - Exchange 2000/2003 oServer.Protocol = ServerProtocol.ExchangeWebDav ' User and password for Exchange User authentication oServer.User = "adminsystem.com\myuser" oServer.Password = "testpassword" ' if your server requires SSL conection, add this line ' oServer.ConnectType = SmtpConnectType.ConnectSSLAuto Dim oMail As SmtpMail = New SmtpMail("TryIt") oMail.From = New MailAddress("myuser@adminsystem.com") oMail.To.Add(New MailAddress("to@adminsystem.com")) oMail.Subject = "test email sent from VB with WebDAV protocol" oMail.TextBody = "test body" Dim oSmtp As SmtpClient = New SmtpClient() oSmtp.SendMail(oServer, oMail) Console.WriteLine("This email has been submitted to server successfully!") Catch exp As Exception onsole.WriteLine("Exception: {0}", exp.Message) End Try End Sub
[C# - Send Email using Standard SMTP protocol] using System; using EASendMail; void SendMail_SMTP() { try { // SMTP server address SmtpServer oServer = new SmtpServer("smtp.adminsystem.com"); // SMTP user authentication oServer.User = "myusername"; oServer.Password = "mypassword"; // specifies the authentication mechanism, AuthAuto is default value // oSmtp.AuthType = SmtpAuthType.AuthAuto; // 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; // set SSL/TLS connection // oServer.ConnectType = SmtpConnectType.ConnectSSLAuto; // set SMTP server port to 587, default value is 25 // oServer.Port = 587; // set SMTP server port to 465, // if 465 port is used, ConnectType should use ConnectSSLAuto or ConnectDirectSSL. // oServer.Port = 465; // set helo domain, default value is current machine name // oServer.HeloDomain = "mymachine.com"; SmtpMail oMail = new SmtpMail("TryIt"); 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"; SmtpClient oSmtp = new SmtpClient(); oSmtp.SendMail(oServer, oMail); Console.WriteLine("This email has been submitted to server successfully!"); } catch(Exception exp) { Console.WriteLine("Exception: {0}", exp.Message); } }
[C# - Send Email using Exchange Web Service - EWS] using System; using EASendMail; void SendMail_Exchange_EWS() { try { // Your Exchange server address SmtpServer oServer = new SmtpServer("exch.emailarchitect.net"); // Set Exchange Web Service protocol (EWS) - Exchange 2007/2010/2013/2016/2019/Office 365 oServer.Protocol = ServerProtocol.ExchangeEWS; // User and password for Exchange authentication oServer.User = "test@emailarchitect.net"; oServer.Password = "testpassword"; // By default, Exchange Web Service requires SSL connection oServer.ConnectType = SmtpConnectType.ConnectSSLAuto; SmtpMail oMail = new SmtpMail("TryIt"); oMail.From = new MailAddress("test@emailarchitect.net"); oMail.To.Add(new MailAddress("to@adminsystem.com")); oMail.Subject = "test email sent from C# with EWS protocol"; oMail.TextBody = "test body"; SmtpClient oSmtp = new SmtpClient(); oSmtp.SendMail(oServer, oMail); Console.WriteLine("This email has been submitted to server successfully!"); } catch (Exception exp) { Console.WriteLine("Exception: {0}", exp.Message); } }
[C# - Send Email using Exchange WebDAV] using System; using EASendMail; void SendMail_Exchange_WebDav() { try { // Your Exchange server address SmtpServer oServer = new SmtpServer("exch.emailarchitect.net"); // Set Exchange WebDAV protocol (EWS) - Exchange 2000/2003 oServer.Protocol = ServerProtocol.ExchangeWebDav; // User and password for Exchange authentication oServer.User = "emailarchitect.net\\test"; oServer.Password = "testpassword"; // If your Exchange WebDav requires SSL connection, please add this line // oServer.ConnectType = SmtpConnectType.ConnectSSLAuto; SmtpMail oMail = new SmtpMail("TryIt"); oMail.From = new MailAddress("test@emailarchitect.net"); oMail.To.Add(new MailAddress("to@adminsystem.com")); oMail.Subject = "test email sent from C# with WebDAV protocol"; oMail.TextBody = "test body"; SmtpClient oSmtp = new SmtpClient(); oSmtp.SendMail(oServer, oMail); Console.WriteLine("This email has been submitted to server successfully!"); } catch (Exception exp) { Console.WriteLine("Exception: {0}", exp.Message); } }
[C++ - Send Email using Standard SMTP Protocol] using namespace System; using namespace EASendMail; void SendMail_SMTP() { try { // SMTP server address SmtpServer ^oServer = gcnew SmtpServer("smtp.adminsystem.com"); // SMTP user authentication oServer->User = "myusername"; oServer->Password = "mypassword"; // specifies the authentication mechanism, AuthAuto is default value // oSmtp.AuthType = SmtpAuthType::AuthAuto; // 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; // set SSL/TLS connection // oServer->ConnectType = SmtpConnectType::ConnectSSLAuto; // set SMTP server port to 587, default value is 25 // oServer->Port = 587; // set SMTP server port to 465, // if 465 port is used, ConnectType should use ConnectSSLAuto or ConnectDirectSSL. // oServer->Port = 465; // set helo domain, default value is current machine name // oServer->HeloDomain = "mymachine.com"; SmtpMail ^oMail = gcnew SmtpMail("TryIt"); 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"; SmtpClient ^oSmtp = gcnew SmtpClient(); oSmtp->SendMail(oServer, oMail); Console::WriteLine("This email has been submitted to server successfully!"); } catch(Exception ^exp) { Console::WriteLine("Exception: {0}", exp->Message); } }
[C++ - Send Email using Exchange Web Service - EWS] using namespace System; using namespace EASendMail; void SendMail_Exchange_EWS() { try { // Your Exchange server address SmtpServer ^oServer = gcnew SmtpServer("exch.emailarchitect.net"); // Set Exchange Web Service Protocol - EWS - Exchange 2007/2010/2013/2016/2019/Office 365 oServer->Protocol = ServerProtocol::ExchangeEWS; // User and password for Exchange Web Service authentication oServer->User = "test@emailarchitect.net"; oServer->Password = "testpassword"; // By default, Exchange Web Service requires SSL connection. oServer->ConnectType = SmtpConnectType::ConnectSSLAuto; SmtpMail ^oMail = gcnew SmtpMail("TryIt"); oMail->From = gcnew MailAddress("test@emailarchitect.net"); oMail->To->Add(gcnew MailAddress("to@adminsystem.com")); oMail->Subject = "test email sent from C++/CLI with EWS protocol"; oMail->TextBody = "test body"; SmtpClient ^oSmtp = gcnew SmtpClient(); oSmtp->SendMail(oServer, oMail); Console::WriteLine("This email has been submitted to server successfully!"); } catch (Exception ^exp) { Console::WriteLine("Exception: {0}", exp->Message); } }
[C++ - Send Email using Exchange WebDAV] using namespace System; using namespace EASendMail; void SendMail_Exchange_WebDav() { try { // Your Exchange server address SmtpServer ^oServer = gcnew SmtpServer("exch.emailarchitect.net"); // Set Exchange WebDav Protocol - Exchange 2000/2003 oServer->Protocol = ServerProtocol::ExchangeWebDav; // User and password for Exchange WebDav authentication oServer->User = "emailarchitect.net\\test"; oServer->Password = "testpassword"; // If your WebDav service requires SSL connection, please add this line // oServer->ConnectType = SmtpConnectType::ConnectSSLAuto; SmtpMail ^oMail = gcnew SmtpMail("TryIt"); oMail->From = gcnew MailAddress("test@emailarchitect.net"); oMail->To->Add(gcnew MailAddress("to@adminsystem.com")); oMail->Subject = "test email sent from C++/CLI with WebDAV protocol"; oMail->TextBody = "test body"; SmtpClient ^oSmtp = gcnew SmtpClient(); oSmtp->SendMail(oServer, oMail); Console::WriteLine("This email has been submitted to server successfully!"); } catch (Exception ^exp) { Console::WriteLine("Exception: {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