A lightweight SMTP server implemented in Go that forwards emails via the Microsoft Graph API.
- Supports both plain text and HTML emails.
- Handles email attachments.
- Logs all activities to a specified log file.
The server requires a configuration file in YAML format. Below is an example GoSMTP.yaml
:
azure:
client_id: "your-client-id"
client_secret: "your-client-secret"
tenant_id: "your-tenant-id"
smtp:
address: ":25"
domain: "localhost"
log_file: "/path/to/log/file.log"
- Clone the repository:
git clone <repository_url> cd smtp_graph_project
- Install dependencies:
go mod tidy
- Build the project:
go build -o GoGraphSMTP main.go
Create a systemd service file gographsmtp.service
with the following content:
[Unit]
Description=GoGraphSmtp SMTP to Graph API Bridge
After=network.target
[Service]
Type=simple
User=root
ExecStart=/usr/local/bin/GoGraphSMTP
Restart=always
RestartSec=10
WorkingDirectory=/etc/GoGraphSMTP
[Install]
WantedBy=multi-user.target
Follow these steps to deploy the service:
-
Copy the binary file:
cp GoGraphSMTP /usr/local/bin/
-
Create a directory for configuration:
mkdir -p /etc/GoGraphSMTP
-
Copy the configuration file:
cp GoSMTP.yaml /etc/GoGraphSMTP/
-
Copy the systemd service file:
cp gographsmtp.service /etc/systemd/system/
-
Reload the systemd configuration:
systemctl daemon-reload
-
Start the service:
systemctl start gographsmtp
-
Enable the service to start on boot:
systemctl enable gographsmtp
-
Check the service status:
systemctl status gographsmtp
Use the following commands to manage the service:
-
Stop the service:
systemctl stop gographsmtp
-
Restart the service:
systemctl restart gographsmtp
-
View service logs:
journalctl -u gographsmtp
- Create a test PHP script or use any SMTP client to test the service.
- Verify logs in the file specified in the
log_file
configuration or withjournalctl
.
- Ensure that your Azure app has the
Mail.Send
permission. - Test the service with a sample email to confirm proper configuration.
MIT License