Skip to content

Instantly share code, notes, and snippets.

@amanjuman
Last active November 18, 2024 10:30
Show Gist options
  • Save amanjuman/1121efff59a69d6d3d76de2b35ba9afa to your computer and use it in GitHub Desktop.
Save amanjuman/1121efff59a69d6d3d76de2b35ba9afa to your computer and use it in GitHub Desktop.
AWS SES Relay with Sendmail
// Update Packages
sudo apt-get update && sudo apt-get -y upgrade && sudo apt dist-upgrade -y && sudo apt-get autoremove -y
// Setup Hostname
hostnamectl set-hostname subdomain.domain.tld
// Create Host Record
sudo nano /etc/hosts
// Add this line
127.0.1.1 subdomain.domain.tld subdomain
// Install SendMail MTA and Mail Utilits
sudo apt install sendmail mailutils sasl2-bin libsasl2-modules
// Make Mail Dir if not exist
sudo mkdir /etc/mail
// Create Mail Authentication Folder
sudo mkdir -m 700 /etc/mail/authinfo/
// Update SES Host and Access KEY and Password
sudo nano /etc/mail/authinfo/awsses-auth
AuthInfo:SES-HOST-ENDPOINT "U:root" "I:ACCESS-ID" "P:ACCESS-KEY" "M:PLAIN"
// Connect SES Relay
sudo echo "Connect:SES-HOST-ENDPOINT RELAY" >> /etc/mail/access
// Generate hash file using Auth File
sudo makemap hash /etc/mail/authinfo.db < /etc/mail/authinfo/awsses-auth
// Regenerate DB File
sudo makemap hash /etc/mail/access.db < /etc/mail/access
// Backup SendMail config File
sudo cp /etc/mail/sendmail.cf /etc/mail/sendmail_cf.backup && cp /etc/mail/sendmail.mc /etc/mail/sendmail_mc.backup
// Edit and Update Config File
sudo nano /etc/mail/sendmail.mc
## SES Config before last three line
define('SMART_HOST', 'SES-HOST-ENDPOINT')dnl
define('RELAY_MAILER_ARGS', 'TCP $h 587')dnl
define('confAUTH_MECHANISMS', 'EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
MASQUERADE_AS('domain.tld')dnl
FEATURE('authinfo', 'hash -o /etc/mail/authinfo.db')dnl
FEATURE(masquerade_envelope)dnl
FEATURE(masquerade_entire_domain)dnl
// Rebuild SendMail
sudo make -C /etc/mail
// Restart SendMail MTA
sudo /etc/init.d/sendmail restart
// Test Mail
/usr/sbin/sendmail -vf [email protected] [email protected]
From: [email protected]
To: [email protected]
Subject: Amazon SES SMTP Relay Test Email
This is a test message sent from Amazon SES using Sendmail.
// Press Clt + D to Send
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment