Send emails to a Microsoft 365 Server with Microsoft Graph in C# and VB.NET
The example below shows how you can use the GemBox.Email library to connect to the Microsoft 365 (Office 365) Server and send an email from your console application by using C# or VB.NET code.
using GemBox.Email;
using GemBox.Email.Graph;
class Program
{
static void Main()
{
// If using the Professional version, put your serial key below.
ComponentInfo.SetLicense("FREE-LIMITED-KEY");
// Create a new email message.
var message = new MailMessage(
new MailAddress("sender@example.com", "Sender"),
new MailAddress("first.receiver@example.com", "First receiver"),
new MailAddress("second.receiver@example.com", "Second receiver"));
// Add additional receivers.
message.Cc.Add(
new MailAddress("third.receiver@example.com", "Third receiver"),
new MailAddress("fourth.receiver@example.com", "Fourth receiver"));
// Add subject and body.
message.Subject = "Send Email in C# and VB.NET";
message.BodyText = "Hi 👋,\n" +
"This message was created and sent with GemBox.Email.\n" +
"Read more about it on https://www.gemboxsoftware.com/email";
// Create a new Graph client and send an email message.
var graphClient = new GraphClient();
graphClient.Authenticate("");
graphClient.ImpersonateUser("");
graphClient.SendMessage(message);
}
}
Imports GemBox.Email
Imports GemBox.Email.Graph
Module Program
Sub Main()
' If using the Professional version, put your serial key below.
ComponentInfo.SetLicense("FREE-LIMITED-KEY")
' Create a new email message.
Dim message As New MailMessage(
New MailAddress("sender@example.com", "Sender"),
New MailAddress("first.receiver@example.com", "First receiver"),
New MailAddress("second.receiver@example.com", "Second receiver"))
' Add additional receivers.
message.Cc.Add(
New MailAddress("third.receiver@example.com", "Third receiver"),
New MailAddress("fourth.receiver@example.com", "Fourth receiver"))
' Add subject and body.
message.Subject = "Send Email in C# and VB.NET"
message.BodyText = "Hi 👋," & vbLf &
"This message was created and sent with GemBox.Email." & vbLf &
"Read more about it on https://www.gemboxsoftware.com/email"
' Create a new Graph client and send an email message.
Dim graphClient = New GraphClient()
graphClient.Authenticate("")
graphClient.ImpersonateUser("")
graphClient.SendMessage(message)
End Sub
End Module

GemBox.Email supports communication with the Microsoft 365 Server, when using the Microsoft Graph API. The following example shows how you can use GemBox.Email to send an email with attachments using Microsoft Graph. Hi 👋, This message was created and sent with: Read more about it on GemBox.Email Overview page. Hi 👋, This message was created and sent with: Read more about it on GemBox.Email Overview page.Send an email with an attachment in Microsoft 365
using GemBox.Email;
using GemBox.Email.Graph;
class Program
{
static void Main()
{
// If using the Professional version, put your serial key below.
ComponentInfo.SetLicense("FREE-LIMITED-KEY");
// Create new email message.
var message = new MailMessage("sender@example.com", "receiver@example.com");
// Add subject.
message.Subject = "Send HTML Email with Image and Attachment";
// Add HTML body with CID embedded image.
string cid = "image001@gembox.com";
message.BodyHtml = "" +
"Imports GemBox.Email
Imports GemBox.Email.Graph
Module Program
Sub Main()
' If using the Professional version, put your serial key below.
ComponentInfo.SetLicense("FREE-LIMITED-KEY")
' Create new email message.
Dim message = New MailMessage("sender@example.com", "receiver@example.com")
' Add subject.
message.Subject = "Send HTML Email with Image and Attachment"
' Add HTML body with CID embedded image.
Dim cid = "image001@gembox.com"
message.BodyHtml = "" &
"

