Use Proxy With Microsoft Graph
The example below shows how you can use the GemBox.Email component to connect to Microsoft 365 (Office 365) Server through a proxy server in C# and VB.NET.
using GemBox.Email;
using GemBox.Email.Graph;
using System;
using System.Net;
class Program
{
static void Main()
{
// If using the Professional version, put your serial key below.
ComponentInfo.SetLicense("FREE-LIMITED-KEY");
// Create the proxy client.
var proxy = new WebProxy("http://proxy.company.com:8080");
// If your proxy requires authentication, set the credentials.
proxy.Credentials = new NetworkCredential("username", "password");
// Create a GraphClient instance that will make network requests through the proxy.
var graphClient = new GraphClient(proxy);
// Authenticate with OAuth 2.0 token.
graphClient.Authenticate("<OAUTH2.0-TOKEN>");
graphClient.ImpersonateUser("<USER-ID-OR-EMAIL>");
// Test the proxy connection by listing folders.
var folders = graphClient.ListFolders();
Console.WriteLine("Successfully connected to Microsoft Graph through proxy!");
Console.WriteLine($"Found {folders.Count} folders:");
}
}
Imports GemBox.Email
Imports GemBox.Email.Graph
Imports System
Imports System.Net
Module Program
Sub Main()
' If using the Professional version, put your serial key below.
ComponentInfo.SetLicense("FREE-LIMITED-KEY")
' Create the proxy client.
Dim proxy As New WebProxy("http://proxy.company.com:8080")
' If your proxy requires authentication, set the credentials.
proxy.Credentials = New NetworkCredential("username", "password")
' Create a GraphClient instance that will make network requests through the proxy.
Dim graphClient As New GraphClient(proxy)
' Authenticate with OAuth 2.0 token.
graphClient.Authenticate("<OAUTH2.0-TOKEN>")
graphClient.ImpersonateUser("<USER-ID-OR-EMAIL>")
' Test the proxy connection by listing folders.
Dim folders = graphClient.ListFolders()
Console.WriteLine("Successfully connected to Microsoft Graph through proxy!")
Console.WriteLine($"Found {folders.Count} folders:")
End Sub
End Module

In corporate network environments, internet traffic is often routed through proxy servers for security and monitoring purposes. To use a proxy with GraphClient
, create a WebProxy
instance with your proxy server details and pass it to the constructor. If your proxy server requires authentication, set the Credentials
property with appropriate username and password.
The acceptAnyCertificate
parameter can be set to true
if you need to bypass SSL certificate validation when connecting to proxies with HTTPS protocol. Please note that HTTPS proxies are only supported on .NET 8.0 or higher versions.