I'm trying to re-write the TO:
header in sent emails with ssmtp
.
I've configured mail sent to root
to be sent via ssmtp
(by creating a symlink at /etc/sendmail
).
It is redirected to the /etc/aliases
entry, but the TO: header is always the user itself, in this case, it is "TO: root".
The SMTP server rejects this alias. I'd like to have the TO: field re-written to a configurable email address.
I have configured: /etc/aliases
, /etc/ssmtp/revaliases
, and /etc/ssmtp/ssmtp.conf
as I expect would work.
Is this possible with ssmtp
?
[UPDATE]
Setup:
yum -y install ssmtp
service sendmail stop
chkconfig --levels 2345 sendmail off
chkconfig --del sendmail
export tmpsm=$(which sendmail)
mv $tmpsm $(echo $tmpsm.bak)
ln -s $(which ssmtp) $tmpsm
groupadd nogroup
useradd ssmtp -g nogroup -s /sbin/nologin -d /nonexistent -c "sSMTP pseudo-user"
chown ssmtp:wheel /etc/ssmtp/ #http://en.wikipedia.org/wiki/Wheel_(Unix_term)
chmod 4750 /etc/ssmtp/ #https://en.wikipedia.org/wiki/Setuid
chown ssmtp:wheel /etc/ssmtp/ /etc/ssmtp/ssmtp.conf
chmod 640 /etc/ssmtp/ssmtp.conf
chown ssmtp:nogroup $(which ssmtp)
chmod 4555 $(which ssmtp)
sed s/root=postmaster/#root=postmaster/ -i /etc/ssmtp/ssmtp.conf
sed s/mailhub=mail/#mailhub=mail/ -i /etc/ssmtp/ssmtp.conf
echo "[email protected]" >> /etc/ssmtp/ssmtp.conf #will route anything that's sent to any user with a UID under 500 (check /etc/passwd) to [email protected]
echo "mailhub=smtp.stackoverflown.com:587" >> /etc/ssmtp/ssmtp.conf
echo "[email protected]" >> /etc/ssmtp/ssmtp.conf
echo "AuthPass=XXXXXXXXX" >> /etc/ssmtp/ssmtp.conf
echo "[email protected]" >> /etc/ssmtp/ssmtp.conf #will rewrite the domain when destined for a domain
echo "[email protected]" >> /etc/ssmtp/ssmtp.conf
echo "FromLineOverride=YES" >> /etc/ssmtp/ssmtp.conf
echo "UseTLS=YES" >> /etc/ssmtp/ssmtp.conf
echo "UseSTARTTLS=Yes" >> /etc/ssmtp/ssmtp.conf
echo "root:[email protected]" >> /etc/ssmtp/revaliases
echo "seccubus:[email protected]" >> /etc/ssmtp/revaliases
#setup send as alias
echo 'root: [email protected]' >> /etc/aliases
echo 'seccubus: [email protected]' >> /etc/aliases
newaliases
Test:
yum -y install mailx
#test baseline:
echo "test" | mail -v -s "$(date)" [email protected]
#test sending to a local user:
echo $(netstat -apn | grep :) | mail -v -s "$(date)" root #<-------------------FAILS to send due to SERVER specific policy! because "TO: root"
#check logs:
tail -f /var/log/maillog
0 Answers