2

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 "root=mbrownnyc@stackexchange.com" >> /etc/ssmtp/ssmtp.conf #will route anything that's sent to any user with a UID under 500 (check /etc/passwd) to mbrownnyc@stackexchange.com
echo "mailhub=smtp.stackoverflown.com:587" >> /etc/ssmtp/ssmtp.conf 
echo "AuthUser=mbrownnyc@stackexchange.com" >> /etc/ssmtp/ssmtp.conf 
echo "AuthPass=XXXXXXXXX" >> /etc/ssmtp/ssmtp.conf 
echo "RewriteDomain=mbrownnyc@stackexchange.com" >> /etc/ssmtp/ssmtp.conf  #will rewrite the domain when destined for a domain
echo "Hostname=mbrownix.mbrownnyc@stackexchange.com" >> /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:mbrownnyc@stackexchange.com" >> /etc/ssmtp/revaliases
echo "seccubus:mbrownnyc@stackexchange.com" >> /etc/ssmtp/revaliases


#setup send as alias
echo 'root: mbrownnyc@stackexchange.com' >> /etc/aliases
echo 'seccubus: mbrownnyc@stackexchange.com' >> /etc/aliases
newaliases

Test:

yum -y install mailx

#test baseline:
echo "test" | mail -v -s "$(date)" mbrownnyc@stackexchange.com
#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
brandeded
  • 1,845
  • 8
  • 32
  • 50
  • I'm not entirely sure what you're trying to do. Are you actually trying to deliver local mail for root to another user? You keep talking about changing the `To:` header. Do you want to actually deliver the mail to another user, or change the `To:` header? – Michael Hampton Oct 19 '18 at 18:07
  • Thanks for replying. Both. I'll update the question with both my config and testing. – brandeded Oct 19 '18 at 18:59
  • I actually have the same problem: The relay server refuses the mail if the DATA-part contains a To:-header without a domain. Did you figure out a solution to this problem? – Niobos Jan 14 '19 at 09:45
  • We're probably using the same email host. I never did figure this out, I think I just accepted this as a limitation, and used the subject to filter in my email client. Sorry! – brandeded Jan 29 '19 at 19:20

0 Answers0