SmtpServer Class


Provides properties and methods for constructing a SMTP server or Exchange Server instance.

System.Object
    EASendMail.SmtpServer

[Visual Basic]
Public Class SmtpServer
[C#]
public class SmtpServer
[C++]
public ref class SmtpServer
[JScript]
public class SmtpServer

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Public Constructors

SmtpServer Constructor Initializes a new instance of the SmtpServer class.

Public Properties

Alias Gets or sets the Exchange user alias for WebDav protocol.
AuthType Gets or sets the smtp user authentication mechanism.
ConnectType Gets or sets the smtp server connection type.
Drafts Gets or sets the Exchange user drafts folder for WebDav protocol.
EHLO Gets or sets using EHLO instead of HELO command.
HeloDomain Gets or sets the domain used in HELO/EHLO command.
MailFrom Gets or sets the e-mail address in MAIL FROM command.
Password Gets or sets the password for user authentication.
PIPELINING Gets or sets using PIPELINING extension with SMTP server.
Port Gets or sets the port of smtp server.
Protocol Gets or sets the protocol of server.
ProxyProtocol Gets or sets the protocol (socks4/socks5/http) for proxy server.
Server Gets or sets the smtp server address (IP or internet domain name).
SocksProxyServer Gets or sets the socks4/5/http proxy server address (IP or internet domain name).
SocksProxyPort Gets or sets the port of socks4/5/http proxy server.
SocksProxyUser Gets or sets the user for proxy user authentication.
SocksProxyPassword Gets or sets the password for proxy user authentication.
User Gets or sets the user for user authentication.

Example

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

[VB - Send Email using SMTP Server]

Imports EASendMail

Sub SendMail()

    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


[C# - Send Email using SMTP Server] using System; using EASendMail; void SendMail() { 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++/CLI - Send Email using SMTP Server] using namespace System; using namespace EASendMail; void SendMail() { 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); } }

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