Configure sendmail to relay on an smtp server

email-serversendmailsmtp

I'm using an ubuntu distribution.

And I installed the sendmail with apt, and edited the /etc/mail/sendmail.mc, and added the lines

define(`SMART_HOST', `ssl0.ovh.net')
FEATURE(`authinfo')

before the line

define(`_USE_ETC_MAIL_')dnl

And also configured the authentication (/etc/mail/authinfo):

AuthInfo:ssl0.ovh.net "U:myemail@mydomain.com" "P:123456" "M:PLAIN"

and run m4 sendmail.mc >sendmail.cf and service sendmail restart

I created a file to test it email.txt:

To: one@ofmyemail.com
From: my@email.com
Subject: Foo Bar

Hello
(empty line)

and I test it with: cat email.txt | /usr/lib/sendmail -bm -t -v

And it fails with:

one@ofmyemail.com... Connecting to [127.0.0.1] via relay...
one@ofmyemail.com... Deferred: Connection refused by [127.0.0.1]

Why is it connecting with 127.0.0.1 instead of the external smtp server (ssl0.ovh.net)?

Best Answer

Sendmail had used to be installed as set root uid program. Sendmail-8.12+ is no longer (by default) installed as set root uid program to avoid security risk.

Sendmail executed by non root user passes messages to sendmail daemon running with root privileges at 127.0.0.1:25. Sendmail executed by non root user uses /etc/mail/submit.cf instead of /etc/mail/sendmail.cf.

https://www.sendmail.com/sm/open_source/security/secure-install/


To test your sendmail.cf configuration as root execute the command below (your test command with -Am added):

cat email.txt | /usr/lib/sendmail -Am -bm -t -v
Related Topic