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 with Attachment in C# and VB.NET

The example shows how to use the GemBox.Email .NET library to create and send a mail message with text and HTML body, and attachments from C# and VB.NET application.

Attachments Screenshot

See the full code below.

using GemBox.Email;
using GemBox.Email.Mime;
using GemBox.Email.Smtp;
using System;
using System.Collections.Generic;

class Sample
    static void Main(string[] args)
        // If using Professional version, put your serial key below.

        // Create new message with specified 'from' and 'to' addresses
        MailMessage message = new MailMessage("", "");

        // Set subject and text body
        message.Subject = "Email message with attachments";
        message.BodyText = "This is a message body.";
        message.BodyHtml = "<h1>This is a message body.</h1>";

        // Add attachments
        message.Attachments.Add(new Attachment("Image.png"));
        message.Attachments.Add(new Attachment("Document.docx"));

        // Initialize new SMTP client and send an email message
        using (SmtpClient smtp = new SmtpClient("<ADDRESS> (e.g."))


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


        Console.WriteLine("Message sent successfully.");
Imports GemBox.Email
Imports GemBox.Email.Mime
Imports GemBox.Email.Smtp

Module Samples

    Sub Main()

        ' If using Professional version, put your serial key below.

        ' Create New message with specified 'from' and 'to' addresses
        Dim message As New MailMessage("", "")

        ' Set subject And text body
        message.Subject = "Test email message with attachments"
        message.BodyText = "This is a test message body."
        message.BodyHtml = "<h1>This is a test message body.</h1>"

        ' Add attachments
        message.Attachments.Add(New Attachment("Image.png"))
        message.Attachments.Add(New Attachment("Document.docx"))

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

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

            smtp.Authenticate("<USERNAME>", "<PASSWORD>")

        End Using

        Console.WriteLine("Message sent successfully.")

    End Sub

End Module

Check next sample.