MailHubRelay implements a distributed email handling architecture designed to facilitate the conversion and transmission of various input formats into Gmail-compatible email communications. The system comprises three primary components with complementary utility scripts for deployment management.
The central relay server component operates as a standalone service or foreground application, implementing the following functionalities:
A command-line interface implementing sendmail-compatible operations:
Web service implementation for form submission processing:
Clone or fork the repository.
Use standard go build process, or use make.sh script to with pre-defined make config for freebsd/amd64 build:
# Build script use for FreeBSD build
./script/make.sh -c mhrs.make # Mail Hub Relay Server
./script/make.sh -c mhrc.make # Mail Hub Relay Client
./script/make.sh -c submitf.make # Submit Form Handler
The installation/uninstallation scripts facilitate deployment.
./install-service.sh [-r] [-l] [-c] <path_to_executable>
./uninstall-service.sh [-l] [-c] <service_name>
Parameters:
-r
: Execute service with root privileges-l
: Create and preserve of log directory-c
: Create and preserve of configuration directoryDeployment example:
./scripts/install-service.sh mhrs # Mail Hub Relay Server
./scripts/install-service.sh submitf # Form Handler
./scripts/install-app.sh mhrc # Mail Hub Relay Client
For running on a privileged port (<1024, e.g. 25), install as root (install-service -r).
Default configuration paths (not configurable):
/usr/local/etc/<service_name>/<service_name>.toml
# Edit /etc/mail/mailer.conf and /usr/local/etc/mail/mailer.conf
sendmail /usr/local/bin/mhrc
send-mail /usr/local/bin/mhrc
mailq /usr/local/bin/mhrc -bp
newaliases /usr/local/bin/mhrc -bi
hoststat /usr/local/bin/mhrc -bh
purgestat /usr/local/bin/mhrc -bp
sysrc sendmail_enable="NO"
sysrc sendmail_submit_enable="NO"
sysrc sendmail_outbound_enable="NO"
sysrc sendmail_msp_queue_enable="NO"
ln -s /usr/local/bin/mhrc /usr/local/sbin/sendmail
ln -s /usr/local/bin/mhrc /usr/sbin/sendmail
Suitable for small-medium servers with low email traffic.
[Gmail SMTP]
|
................................................ [Internet] .................
| ^ ^ ^
v v | v
................................................ [Firewall] .................
| ^ ^ ^
v v | |
......................................................:SSL [NGINX] |:TLS
| ^ ^ |
v v | v
[MHRC] [SubmitF] [Local Apps] [Website] [MHRS]
| | | ^
v v v |
-------------------------------------------------------------------
Data Flow Patterns:
A. Web Form Submission Path: Website form submission -> NGINX -> SubmitF -> MHRS -> Gmail SMTP
B. Local Application Path: Local Apps -> MHRS -> Gmail SMTP
C. Legacy Application Path: Sendmail Apps -> MHRC -> MHRS -> Gmail SMTP
Foreground execution:
mhrs
Standard sendmail syntax support:
# Direct recipient specification
echo "Message content" | mhrc user@example.com
# Header-based routing
echo -e "To: user@example.com\nSubject: Test\n\nMessage" | mhrc -t
# Subject specification
echo "Message content" | mhrc -s "Subject" user@example.com
Foreground execution:
submitf
nginx configuration example:
# Contact form submission endpoint with rate limiting
location /submit {
proxy_pass http://localhost:8845;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
limit_req zone=one burst=5 nodelay;
}
async function submitForm(event) {
event.preventDefault();
const formData = {
name: document.getElementById('name').value,
email: document.getElementById('email').value,
message: document.getElementById('message').value
};
try {
const response = await fetch('http://localhost:8845/submit', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(formData)
});
if (!response.ok) {
throw new Error('Submission failed');
}
alert('Form submitted successfully');
} catch (error) {
console.error('Error:', error);
alert('Failed to submit form');
}
}
This project emerged from challenges in setting up mail servers in cloud environments. After experimenting with various solutions, several issues became apparent:
MailHubRelay offers a streamlined solution by acting as an aggregator and mail agent for automated emails, relaying them through Gmail's SMTP service.
MIT license