4

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
  • 34,341
  • 38
  • 97
  • 191
Bobface
  • 151
  • 3
  • 14
  • 1
    You should use `ssmtp`. – fkraiem Jan 17 '17 at 12:06
  • Does it work with fail2ban? – Bobface Jan 17 '17 at 12:12
  • Does it say something in `/var/log/syslog`? – FatalMerlin Jan 17 '17 at 12:13
  • @FatalMerlin Oh yes, actually there is something. I added it to my post. – Bobface Jan 17 '17 at 12:22
  • @Bobface hm, I don't think that the hostname should have anything to do with it. Try to send a test email with `echo "This is a Testmail :)" | mailx user@mailserver.tld` (Install mailx with `sudo apt-get install mailutils` if you don't have it) – FatalMerlin Jan 17 '17 at 12:31
  • @FatalMerlin I just noticed `dsn=5.0.0, stat=Service unavailable` in the 5th line. Does that mean that there is something wrong with the dns name resolution? – Bobface Jan 17 '17 at 12:33
  • @Bobface Please try to reconfigure sendmail using [this guide](http://stackoverflow.com/questions/10359437/sendmail-how-to-configure-sendmail-on-ubuntu). – FatalMerlin Jan 17 '17 at 12:33

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
  • 34,341
  • 38
  • 97
  • 191
  • How do I find out what I have to enter for `your.isp.net`? – Bobface Jan 17 '17 at 13:28
  • Search on the home page of your Internet service provider for "SMTP Server" – Fabby Jan 17 '17 at 13:32
  • It is a rented server hosted by a company. How can I find out their ISP? Is there a way to find it out with commands or do I have to contact them? – Bobface Jan 17 '17 at 13:46
  • you have to search their web site or ask them through a support ticket. – Fabby Jan 17 '17 at 13:48
  • Don't thank me @Bobface, just press the little grey checkmark to the left of the question turning it to a beautiful green! ;) – Fabby Jan 17 '17 at 13:55
  • 1
    I will now try it out, if it works I will of course :) – Bobface Jan 17 '17 at 13:57
  • ´m4 sendmail.mc > sendmail.cf´ prints `m4:sendmail.mc:102: cannot open `/usr/share/sendmail/cf/feature/'authinfo'.m4': No such file or directory`. I followed your guide step by step. – Bobface Jan 17 '17 at 14:03
  • Oops, my fault. Works now! – Bobface Jan 17 '17 at 16:20
  • Fabby, @Bobface: Does this work, as written? Unlike most languages, [quotes](https://www.gnu.org/software/m4/manual/m4.html#Quoted-strings) in [M4](https://en.wikipedia.org/wiki/M4_(computer_language)) are [*opened* by a backtick (`\``)](http://www.sendmail.com/sm/open_source/docs/m4/intro_m4.html) and closed by a single quote (`'`), unless [changed with `changequote`](https://www.gnu.org/software/m4/manual/m4.html#Changequote). [On SO](https://stackoverflow.com/q/10359437), some users [posted](https://stackoverflow.com/a/12808170) [answers](https://stackoverflow.com/a/21002751) about that. – Eliah Kagan Jan 17 '17 at 21:26
  • @EliahKagan Yes exactly, that was the mistake. Although I thought that I accidently changed it so I wrote "my mistake" although it was already like this in Fabbys answer. :) I will edit it now. – Bobface Jan 17 '17 at 21:55
  • @bobface. Dzmn, you're quick! My turn to thank you now! :-) +5 rep again... – Fabby Jan 17 '17 at 21:58