Add a Calendar to Email in C# and VB.NET

GemBox.Email enables you to add a Calendar into a MailMessage.Calendars collection, which can be later sent or saved to a file.

You can add multiple calendars to a single email or retrieve all calendars from a loaded or received email.

The following example shows how to create a new Calendar, add it to a MailMessage and save it to a file.

Screenshot of generated Email with Calendar
Adding a Calendar to Email in C# and VB.NET
using System;
using System.Linq;
using GemBox.Email;
using GemBox.Email.Calendar;

class Program
{
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        // Create new message.
        MailMessage message = new MailMessage("sender@example.com", "receiver@example.com");

        message.Subject = "Mail Message With Calendar";
        message.BodyText = "Hi! I am sending you my calendar.";

        // Create new calendar.
        Calendar calendar = new Calendar();
        Event ev = new Event();
        ev.Organizer = message.Sender;
        ev.Name = "GemBox Meeting Request";
        ev.Start = new DateTime(2018, 1, 10, 9, 0, 0, DateTimeKind.Utc);
        ev.End = new DateTime(2018, 1, 12, 18, 0, 0, DateTimeKind.Utc);
        ev.Attendees.Add(message.To.First());
        calendar.Events.Add(ev);

        // Add calendar to the mail message.
        message.Calendars.Add(calendar);

        message.Save("Add To Message.eml");
    }
}
Imports System
Imports System.Linq
Imports GemBox.Email
Imports GemBox.Email.Calendar

Module Program

    Sub Main()

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

        ' Create new message.
        Dim message As New MailMessage("sender@example.com", "receiver@example.com")

        message.Subject = "Mail Message With Calendar"
        message.BodyText = "Hi! I am sending you my calendar."

        ' Create new calendar.
        Dim calendar As New Calendar()
        Dim ev As New [Event]()
        ev.Organizer = message.Sender
        ev.Name = "GemBox Meeting Request"
        ev.Start = New DateTime(2018, 1, 10, 9, 0, 0, DateTimeKind.Utc)
        ev.End = New DateTime(2018, 1, 12, 18, 0, 0, DateTimeKind.Utc)
        ev.Attendees.Add(message.To.First)
        calendar.Events.Add(ev)

        ' Add calendar to the mail message.
        message.Calendars.Add(calendar)

        message.Save("Add To Message.eml")
    End Sub
End Module

Check next example or download examples from GitHub.