Deploying Sendmail
Introduction
Sendmail is one of the oldest and most widely-used mail transfer agents (MTA) on the Internet. First released in 1983, Sendmail has been a foundational component of email infrastructure, handling the routing and delivery of email messages. While newer alternatives like Postfix and Exim have gained popularity, Sendmail remains a robust choice for organizations requiring a proven, highly configurable email delivery system.
Sendmail’s architecture is built around flexibility and power, with its m4 macro-based configuration system allowing administrators to customize virtually every aspect of mail handling. The software supports multiple authentication methods, encryption, and integrates with various spam filtering and antivirus solutions.
Key highlights of Sendmail:
- Proven Reliability: Decades of production use worldwide
- Highly Configurable: Extensive customization through m4 macros
- SMTP Support: Full implementation of SMTP and ESMTP protocols
- TLS Encryption: Support for encrypted mail transport
- Authentication: SMTP AUTH support with various mechanisms
- Milter Interface: Integration with mail filters for spam and virus scanning
- Virtual Hosting: Support for multiple domains
- Queue Management: Sophisticated message queueing and retry logic
- 100% Open Source: Licensed under Sendmail License
This guide covers deploying Sendmail on Klutch.sh as a relay for application email sending.
Why Deploy Sendmail on Klutch.sh
Deploying Sendmail on Klutch.sh provides several advantages:
Simplified Deployment: Klutch.sh handles container orchestration while you focus on mail configuration.
Persistent Storage: Attach volumes for mail queues and configuration that survive restarts.
Scalable Resources: Allocate appropriate resources based on email volume.
Internal Mail Relay: Use as a relay for other applications deployed on Klutch.sh.
Prerequisites
Before deploying Sendmail on Klutch.sh, ensure you have:
- A Klutch.sh account
- A GitHub account with a repository for your Sendmail configuration
- Basic familiarity with Docker and email systems
- Understanding of DNS records (SPF, DKIM, DMARC)
- (Optional) External SMTP relay credentials for production use
Important Considerations
Note: Running a mail server in a containerized environment has limitations:
- Many cloud providers block port 25 to prevent spam
- Proper email delivery requires correct DNS configuration (PTR records, SPF, DKIM)
- Consider using Sendmail as a relay to an external SMTP service
For production email, consider using Sendmail as a relay to services like:
- Amazon SES
- SendGrid
- Mailgun
- Your organization’s SMTP server
Preparing Your Repository
Create a GitHub repository with your Sendmail configuration.
Repository Structure
sendmail-deploy/├── Dockerfile├── sendmail.mc└── .dockerignoreCreating the Dockerfile
Create a Dockerfile in the root of your repository:
FROM alpine:latest
# Install sendmail and dependenciesRUN apk add --no-cache sendmail sendmail-cf cyrus-sasl cyrus-sasl-plain
# Create required directoriesRUN mkdir -p /var/spool/mqueue /var/spool/clientmqueue /etc/mail
# Copy configurationCOPY sendmail.mc /etc/mail/sendmail.mc
# Generate sendmail.cf from sendmail.mcWORKDIR /etc/mailRUN m4 /usr/share/sendmail/cf/m4/cf.m4 sendmail.mc > sendmail.cf
# Set permissionsRUN chmod 644 /etc/mail/sendmail.cf && \ chown root:smmsp /var/spool/clientmqueue && \ chmod 770 /var/spool/clientmqueue
# Expose SMTP portEXPOSE 25 587
# Start sendmailCMD ["sendmail", "-bd", "-q15m"]Creating sendmail.mc Configuration
Create a basic sendmail.mc for relay operation:
divert(-1)divert(0)dnlVERSIONID(`Klutch.sh Sendmail Configuration')dnlOSTYPE(linux)dnl
dnl # Define smart host for relayingdefine(`SMART_HOST', `[smtp.example.com]')dnl
dnl # Enable SMTP authentication for relaydefine(`RELAY_MAILER_ARGS', `TCP $h 587')dnldefine(`ESMTP_MAILER_ARGS', `TCP $h 587')dnl
dnl # Authentication settingsdefine(`confAUTH_MECHANISMS', `PLAIN LOGIN')dnlFEATURE(`authinfo', `hash -o /etc/mail/authinfo.db')dnl
dnl # TLS settingsdefine(`confCACERT_PATH', `/etc/ssl/certs')dnldefine(`confCACERT', `/etc/ssl/certs/ca-certificates.crt')dnl
dnl # Accept connections from anywhere (for container networking)DAEMON_OPTIONS(`Port=smtp, Name=MTA')dnlDAEMON_OPTIONS(`Port=587, Name=MSA, M=Ea')dnl
dnl # Domain masqueradingMASQUERADE_AS(`yourdomain.com')dnlFEATURE(masquerade_envelope)dnl
dnl # Local deliveryFEATURE(`local_procmail', `/usr/bin/procmail')dnl
MAILER(local)dnlMAILER(smtp)dnlEnvironment Variables Reference
| Variable | Required | Default | Description |
|---|---|---|---|
SMART_HOST | No | - | Upstream SMTP server for relaying |
SMTP_USER | No | - | Username for SMTP relay authentication |
SMTP_PASSWORD | No | - | Password for SMTP relay authentication |
MASQUERADE_DOMAIN | No | - | Domain for email masquerading |
Deploying Sendmail on Klutch.sh
- Configure the service for internal access from other Klutch.sh apps
Configure Your SMTP Relay
If using an external relay, gather your SMTP credentials and server details.
Push Your Repository to GitHub
Initialize and push your repository:
git initgit add Dockerfile sendmail.mc .dockerignoregit commit -m "Initial Sendmail deployment configuration"git remote add origin https://github.com/yourusername/sendmail-deploy.gitgit push -u origin mainCreate a New Project on Klutch.sh
Navigate to the Klutch.sh dashboard and create a new project with a descriptive name like “sendmail” or “mail-relay”.
Create a New App
Within your project, create a new app. Connect your GitHub account and select your Sendmail repository.
Configure Traffic
For internal relay use:
Set Environment Variables
Configure relay settings:
| Variable | Value |
|---|---|
SMART_HOST | Your SMTP relay server |
SMTP_USER | Relay authentication username |
SMTP_PASSWORD | Relay authentication password |
Attach Persistent Volumes
Add the following volume:
| Mount Path | Recommended Size | Purpose |
|---|---|---|
/var/spool/mqueue | 5 GB | Mail queue storage |
Deploy Your Application
Click Deploy to start the build process.
Using Sendmail as a Relay
Configuring Applications
Point your applications to use Sendmail for outgoing email:
- SMTP Host: Your Sendmail service internal address
- SMTP Port: 25 or 587
- Authentication: As configured (if any)
Testing Email Delivery
Send a test email using the sendmail command:
echo "Subject: Test Email" | sendmail -v recipient@example.comQueue Management
View the mail queue:
mailqForce queue processing:
sendmail -qTroubleshooting
Email Not Delivering
Symptoms: Emails stay in queue indefinitely.
Solutions:
- Check SMART_HOST configuration
- Verify relay authentication credentials
- Review
/var/log/maillogfor errors - Ensure the relay server accepts connections
Authentication Failures
Symptoms: Relay rejects authentication.
Solutions:
- Verify credentials are correct
- Check that authentication mechanism matches relay requirements
- Ensure TLS is properly configured
DNS Issues
Symptoms: Domain lookup failures.
Solutions:
- Verify container has DNS access
- Check resolver configuration
- Test with direct IP addresses
Additional Resources
Conclusion
Deploying Sendmail on Klutch.sh provides a reliable mail relay for your applications. While Sendmail offers extensive customization, using it as a relay to an external SMTP service provides the best balance of reliability and deliverability in a containerized environment.