This middleware allows applications using legacy Basic Authentication to send emails via Microsoft Graph API.
It includes support for BCC recipients and consolidates emails sent to different recipient types (To, CC, and BCC) to ensure the email is processed and sent only when the QUIT command is issued.
To configure the application, you need a config.ini file in the same folder as the app. Below is an example template:
[MicrosoftGraph]
TenantID = <YourTenantId>
ClientID = <YourClientId>
ClientSecret = <YourClientSecret>
Scope = https://graph.microsoft.com/.default
[Server]
SMTPPort = 2525
Host = 127.0.0.1[MicrosoftGraph]
TenantID = abc123.onmicrosoft.com
ClientID = 11111111-2222-3333-4444-555555555555
ClientSecret = supersecretkey
Scope = https://graph.microsoft.com/.default
[Server]
SMTPPort = 2525
Host = 127.0.0.1- The default SMTP port is
2525. - Ensure the
TenantID,ClientID, andClientSecretare properly set for your Microsoft Graph configuration.
Simply build and run the application:
go build -o smtpservice.exe
./smtpservice.exeThe application will run as a standalone app.
You can install the application as a Windows service either using the built-in installer logic or manually using sc.exe.
Run the following command:
smtpservice.exe install <serviceName> <displayName> <description>Example:
smtpservice.exe install MySMTPService "SMTP Relay Server" "Relays emails through Graph API"This registers the service as MySMTPService in the Windows Services Manager with the specified display name and description.
Alternatively, to manually create the service:
- Open the Command Prompt (Admin).
- Run the following command:
sc create MySMTPService binPath="C:\path\to\smtpservice.exe" DisplayName="SMTP Relay Server"
- Start the service:
sc start MySMTPService
You can also manage the service using the Services Manager GUI:
- Press
Win + R, typeservices.msc, and press Enter. - Locate your service (
SMTP Relay Server), then choose Start, Stop, or configure it.
Use the Service Control Manager or run the following commands:
Start the service:
sc start MySMTPServiceStop the service:
sc stop MySMTPServiceYou can remove the service using the application's built-in uninstall logic or sc.exe.
Using the Application:
smtpservice.exe remove MySMTPServiceUsing sc.exe:
sc delete MySMTPServiceTransfer your compiled binary to /usr/local/bin:
sudo mv smtpservice /usr/local/bin/Make sure the binary is executable:
sudo chmod +x /usr/local/bin/smtpserviceCreate a service file for systemd in /etc/systemd/system/smtpservice.service:
sudo nano /etc/systemd/system/smtpservice.serviceAdd the following content:
[Unit]
Description=SMTP Relay Server
After=network.target
[Service]
ExecStart=/usr/local/bin/smtpservice
Restart=always
RestartSec=5
User=nobody # Change this to the appropriate user
Group=nogroup # Change this to the appropriate group
WorkingDirectory=/usr/local/bin/
[Install]
WantedBy=multi-user.targetNotes:
- Replace
UserandGroupwith the appropriate user/group if required (e.g.,smtpuser). ExecStartmust point to the absolute path of your binary.
-
Reload the systemd daemon to recognize the new unit file:
sudo systemctl daemon-reload
-
Enable the service to start at boot:
sudo systemctl enable smtpservice -
Start the service:
sudo systemctl start smtpservice
-
Check the status of the service:
sudo systemctl status smtpservice
To view logs for the service, use:
sudo journalctl -u smtpserviceTo uninstall the service:
-
Stop the service:
sudo systemctl stop smtpservice
-
Disable it:
sudo systemctl disable smtpservice
-
Remove the systemd unit file:
sudo rm /etc/systemd/system/smtpservice.service
-
Reload systemd:
sudo systemctl daemon-reload
To cross-compile the application for Linux from a Windows development machine, use one of the following methods:
set GOOS=linux
set GOARCH=amd64
go build -o smtpservice$env:GOOS="linux"
$env:GOARCH="amd64"
go build -o smtpserviceGOOS=linux GOARCH=amd64 go build -o smtpserviceIf targeting ARM (e.g., Raspberry Pi):
GOOS=linux GOARCH=arm GOARM=7 go build -o smtpservice1. Permission Denied (Linux or Windows):
- Linux: Run commands with
sudoto avoid permission issues when managing services. - Windows: Ensure the application is launched as an Administrator.
2. Service Fails to Start:
- Check the application logs (
journalctl -u smtpserviceon Linux or Windows Event Viewer). - Verify that
config.iniexists and is configured correctly.
3. Missing config.ini File:
- Ensure
config.iniis in the same directory as the application.
We welcome contributions to this project! Please refer to the LICENSE file for more details on how you can contribute.
This project is licensed under the terms of the MIT License. See the LICENSE file for more details.
For support and feature requests, please open an issue in the repository's issue tracker.