GemBox.Email is a .NET component that enables you to read, write, receive, and send emails from your .NET applications using one simple API.

SMTP Email Client connection in C# and VB.NET

The Simple Mail Transfer Protocol (SMTP) is the only standard protocol for sending mail messages over the Internet. Although it was defined in RFC 821 more than 30 years ago, it is still used today, mainly due to its simplicity.

The following example shows how to connect to and authenticate with a remote server using the SmtpClient class in C# and VB.NET.

Screenshot
Connect with SMTP client Screenshot

See the full code below.

using GemBox.Email;
using GemBox.Email.Security;
using GemBox.Email.Smtp;
using System;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;

class Sample
{
    [STAThread]
    static void Main(string[] args)
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        using (SmtpClient smtp = new SmtpClient("<ADDRESS> (e.g. smtp.gmail.com)"))
        {
            // Connect to mail server
            smtp.Connect();
            Console.WriteLine("Connected.");

            // Authenticate with specified username and password
            // (SmtpClient will use strongest possible authentication mechanism)
            smtp.Authenticate("<USERNAME>", "<PASSWORD>");
            Console.WriteLine("Authenticated.");
        }
    }
}
Imports System.Net.Security
Imports System.Security.Cryptography.X509Certificates
Imports GemBox.Email
Imports GemBox.Email.Smtp

Module Samples

    Sub Main()

        ' If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY")

        Using smtp As New SmtpClient("<ADDRESS> (e.g. smtp.gmail.com)")

            ' Connect to mail server
            smtp.Connect()
            Console.WriteLine("Connected.")

            ' Authenticate with specified username and password
            ' (SmtpClient will use strongest possible authentication mechanism)
            smtp.Authenticate("<USERNAME>", "<PASSWORD>")
            Console.WriteLine("Authenticated.")

        End Using

    End Sub

End Module

Check next sample.