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

Send Email in C#, VB.NET and ASP.NET

The following example shows how to create an email message with two body versions, text and HTML, and one image as an attachment using GemBox.Email library.

The example also shows how to send email message in C# and VB.NET using SmtpClient.

SmtpClient can also be used to send email messages from ASP.NET applications.

Screenshot
Send Screenshot

See the full code below.

using GemBox.Email;
using GemBox.Email.Imap;
using GemBox.Email.Mime;
using GemBox.Email.Pop;
using GemBox.Email.Smtp;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;

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

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

        // Create new email message
        MailMessage message = new MailMessage(new MailAddress("sender@example.com", "Sender"),
                                              new MailAddress("first.receiver@example.com", "First receiver"));

        // Add second receiver to CC and set subject
        message.Cc.Add(new MailAddress("second.receiver@example.com", "Second receiver"));
        message.Subject = "GemBox.Email .NET component";

        // Add HTML and text body
        message.BodyHtml = "<html>" +
                              "<body>" +
                                 "<p>Hi!<br/><br/>This message was created and sent with " +
                                    "<b>GemBox.Email .NET component</b>.<br/>" +
                                    "More info can be found at <a href=\"http://www.gemboxsoftware.com/\">" +
                                    "GemBox Software website</a>." +
                                 "</p>" +
                              "</body>" +
                           "</html>";

        message.BodyText = "Hi!\r\n" +
                           "\r\n" +
                           "This message was created and sent with GemBox.Email .NET component.\r\n" +
                           "More info can be found at http://www.gemboxsoftware.com/.";

        // Add attachment
        message.Attachments.Add(new Attachment("Picture.jpg"));

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

        // Initialize new SMTP client and send an email message
        using (SmtpClient smtp = new SmtpClient("<ADDRESS> (e.g. smtp.gmail.com)"))
        {
            smtp.Connect();
            Console.WriteLine("Connected.");

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

            smtp.SendMessage(message);
        }

        Console.WriteLine("Message sent successfully.");
    }
}
Imports System.Globalization
Imports System.Text
Imports GemBox.Email
Imports GemBox.Email.Imap
Imports GemBox.Email.Mime
Imports GemBox.Email.Pop
Imports GemBox.Email.Smtp

Module Samples

    Sub Main()

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

        Console.WriteLine("Creating message...")

        ' Create new email message
        Dim message As New MailMessage(New MailAddress("sender@example.com", "Sender"),
                                       New MailAddress("first.receiver@example.com", "First receiver"))

        ' Add second receiver to CC And set subject
        message.Cc.Add(New MailAddress("second.receiver@example.com", "Second receiver"))
        message.Subject = "GemBox.Email .NET component"

        ' Add HTML And text body
        message.BodyHtml = "<html>" &
                              "<body>" &
                                "<p>Hi!<br/><br/>This message was created and sent with " &
                                  "<b>GemBox.Email .NET component</b>.<br/>" &
                                  "More info can be found at <a href=""http://www.gemboxsoftware.com/"">" &
                                  "GemBox Software website</a>." &
                                "</p>" &
                              "</body>" &
                            "</html>"

        message.BodyText = "Hi!" & vbCrLf &
                           vbCrLf &
                           "This message was created and sent with GemBox.Email .NET component." & vbCrLf &
                           "More info can be found at http://www.gemboxsoftware.com/."

        ' Add attachment
        message.Attachments.Add(New Attachment("Picture.jpg"))

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

        ' Initialize new SMTP client and send an email message
        Using smtp As New SmtpClient("<ADDRESS> (e.g. smtp.gmail.com)")
            smtp.Connect()
            Console.WriteLine("Connected.")

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

            smtp.SendMessage(message)
        End Using

        Console.WriteLine("Message sent successfully.")

    End Sub

End Module

Check next sample.