5

I want to use sendmail so that fail2ban can send me notifications. I have read multiple guides on how to set it up, but I cannot get it to work.

What I have done so far:

  1. apt-get install sendmail
  2. Modified /etc/hosts: "127.0.0.1 localhost" => "127.0.0.1 localhost localhost.localdomain MYHOSTNAME". I think the error could be here. Since I do not have a domainname, the output of hostname is the IP-Adress the wrong way round. So if my IP-Adress was 1.2.3.4, hostname outputs 4-3-2-1. That's what I entered for "MYHOSTNAME".
  3. Reboot
  4. sudo sendmailconfig.

Still, sendmail is not sending and /var/log/mail.log is empty.

Output of var/log/syslog (everything in upper-letters has been modified by me):

Jan 17 11:58:11 MY-I-P-ADRESS sendmail[1814]: v0HBwBK4001814: from=fail2ban, size=100100, class=0, nrcpts=1, msgid=<201701171158.v0HBwBK4001814@localhost.localdomain>, relay=root@localhost
Jan 17 11:58:11 MY-I-P-ADRESS sendmail[1814]: v0HBwBK4001814: to=MY.MAIL@ADRESS.COM, delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=130100, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (v0HBwB0U001819 Message accepted for delivery)
Jan 17 11:58:12 MY-I-P-ADRESS sendmail[1799]: v0HBtjwr001799: from=root, size=0, class=0, nrcpts=2, relay=root@localhost
Jan 17 11:58:12 MY-I-P-ADRESS sm-mta[1821]: STARTTLS=client, relay=mx3.hotmail.com, version=TLSv1/SSLv3, verify=FAIL, cipher=ECDHE-RSA-AES256-SHA384, bits=256/256
Jan 17 11:58:13 MY-I-P-ADRESS sm-mta[1821]: v0HBwB0U001819: to=<MY.EMAIL@ADRESS.COM>, delay=00:00:02, xdelay=00:00:02, mailer=esmtp, pri=220357, relay=mx3.hotmail.com. [65.55.37.120], dsn=5.0.0, stat=Service unavailable
Jan 17 11:58:13 MY-I-P-ADRESS sm-mta[1821]: v0HBwB0U001819: to=<fail2ban@localhost.localdomain>, delay=00:00:02, mailer=local, pri=220357, dsn=5.1.1, stat=User unknown
Jan 17 11:58:13 MY-I-P-ADRESS sm-mta[1821]: v0HBwB0U001819: to=postmaster, delay=00:00:02, mailer=local, pri=220357, dsn=5.1.1, stat=User unknown
Jan 17 11:58:13 MY-I-P-ADRESS sm-mta[1821]: v0HBwD0U001821: to=MAILER-DAEMON, delay=00:00:00, mailer=local, pri=0, dsn=5.1.1, stat=User unknown
Jan 17 11:58:13 MY-I-P-ADRESS sm-mta[1821]: v0HBwD0U001821: to=postmaster, delay=00:00:00, mailer=local, pri=0, dsn=5.1.1, stat=User unknown
Jan 17 11:58:13 MY-I-P-ADRESS sm-mta[1821]: v0HBwD0V001821: to=MAILER-DAEMON, delay=00:00:00, mailer=local, pri=0, dsn=5.1.1, stat=User unknown
Jan 17 11:58:13 MY-I-P-ADRESS sm-mta[1821]: v0HBwD0U001821: Saved message in /var/lib/sendmail/dead.letter
Fabby
  • 35,017
Bobface
  • 171

1 Answers1

4

When you typed in sudo sendmailconfig, you should have been prompted to configure sendmail.

For reference, the files that are updated during configuration are located at the following (in case you want to update them manually):

/etc/mail/sendmail.conf
/etc/cron.d/sendmail
/etc/mail/sendmail.mc

You can test sendmail to see if it is properly configured and setup by typing the following into the command line:

$ echo "My test email being sent from sendmail" | /usr/sbin/sendmail myemail@domain.com

The following will allow you to add smtp relay to sendmail:

#Change to your mail config directory:
cd /etc/mail

#Make a auth subdirectory
mkdir auth
chmod 700 auth

#Create a file with your auth information to the smtp server
cd auth
touch client-info

#In the file, put the following, matching up to your Internet Service Provider's smtp server:
AuthInfo:your.isp.net "U:root" "I:user" "P:password"

#Generate the Authentication database, make both files readable only by root
makemap hash client-info < client-info
chmod 600 client-info
cd ..

#Add the following lines to sendmail.mc. Make sure you update your smtp server
define(`SMART_HOST',`your.isp.net')dnl
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
FEATURE(`authinfo',`hash /etc/mail/auth/client-info')dnl

#Invoke creation sendmail.cf
m4 sendmail.mc > sendmail.cf

#Restart the sendmail daemon
service sendmail restart

Copied from sendmail: how to configure sendmail on ubuntu? on Stack Overflow, answer by Venice, but modified to change opening ' quotes to `. (That question was too old to migrate here.)

Fabby
  • 35,017