Send Email with SMTP in C# and VB.NET

The example shows how to send a mail message using the SmtpClient class.

Screenshot
Send Message 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)"))
        {
            smtp.Connect();
            Console.WriteLine("Connected.");

            smtp.Authenticate("<USERNAME>", "<PASSWORD>");
            Console.WriteLine("Authenticated.");

            // Create new message
            MailMessage message = new MailMessage("sender@example.com", "receiver@example.com");
            message.Subject = "SMTP test message";
            message.BodyText = "This is test message body.";

            Console.WriteLine("Sending message...");

            // Send message
            smtp.SendMessage(message);

            Console.WriteLine("Message sent.");
        }
    }
}
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)")

            smtp.Connect()
            Console.WriteLine("Connected.")

            smtp.Authenticate("<USERNAME>", "<PASSWORD>")
            Console.WriteLine("Authenticated.")

            ' Create New message
            Dim message As New MailMessage("sender@example.com", "receiver@example.com")
            message.Subject = "SMTP test message"
            message.BodyText = "This is test message body."

            Console.WriteLine("Sending message...")

            ' Send message
            smtp.SendMessage(message)

            Console.WriteLine("Message sent.")

        End Using

    End Sub

End Module