A basic .NET-based background worker service for Windows intended to act as a simple and to-the-point SMTP relay for applications, services, and devices that don't natively support the Graph API, allowing these devices to still send mail in a modern and secure way.
The application is structured into two parts: the SmtpServer for receiving SMTP messages, and a Graph API client built using Microsoft's Graph SDK. Each component is configured by a separate section of the settings file as described in the next section.
At this time, the SmtpServer component of this relay service is only set up for receiving plain and unencrypted SMTP messages on a user-configurable port. Although this is part of the design intent, care should be taken to ensure that the unencrypted traffic being received from the relay is protected from malicious intent. Ideally, the relay should be installed on the source system that is sending outgoing mail.
Note This section of the README is under construction, but in short, an App Registration needs to be created in Azure Active Directory with the
Mail.Send
permission for the Microsoft Graph API. A client secret must then be created for the app registration which is then provided in the relay's configuration file in theAzureClientSecret
setting. Other methods of authentication are not currently supported.Warning Although the Graph API
Mail.Send
should function properly as a user-level permission configured for the appropriate account, the app has only be tested using an Application-level permission with admin consent granted for the organization. However, application access policies may be added separately by administrators to restrict the app registration in question to specific mailboxes.
Warning The configuration file contains sensitive client access secrets, is removed on uninstall, and is overwritten on upgrade. Ensure all data used in your configuration file is backed up to a secure location.
The configuration file for the service is named appsettings.json
. When built from code, it will be present in the output directory of the built executable. When installed using the provided MSI installer, it will be located in %PROGRAMDATA%\JM-A21\GraphMailRelay
. Starting the application while some of these settings are null or missing will result in the application writing errors to the console and the Windows Application
event log before shutting down.
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"EventLog": {
"LogLevel": {
"Default": "Information",
"Microsoft.Hosting.Lifetime": "Warning"
}
},
"SmtpConfiguration": {
"ServerName": "localhost",
"ServerPort": 25,
"AllowedSenderAddresses": [
"127.0.0.1",
"localhost"
]
},
"GraphConfiguration": {
"AzureTenantId": "00000000-0000-0000-0000-000000000000",
"AzureClientId": "00000000-0000-0000-0000-000000000000",
"AzureClientSecret": "rWe0V3DOjSeHr0GRonWE_FakeSecret_RMpXkZaHVBSYRjhqdmGi",
"AzureMailUser": "relayagent@contoso.com",
"EnvironmentName": "GraphGlobal",
"HttpResponseCapture": false
}
}
This section of the file configures the SmtpServer component of the relay application. The default settings in this section are sufficient for receiving mail from a local application or service via either localhost
or 127.0.0.1
on port 25
, but the settings may be modified per your needs as described below.
This section of the file configures the Graph API client component of the relay application. Most settings in this section are defaulted as null
on a fresh install and must be configured for the relay to operate.
Note All GUIDs referenced below must be in format "00000000-0000-0000-0000-000000000000" (no
{}
curly braces) and are not case-sensitive.Note All location notes below are as of 2023-03-23 in the Office 365 Global environment and may not remain accurate in the future.
"GraphGlobal"
for standard / commercial Office 365 tenants."GraphUSGovL4"
for US Government L4 (also known as GCC High).true
or false
.