在没有 Web 服务器的服务器上设置 Sendmail

在没有 Web 服务器的服务器上设置 Sendmail

我想使用sendmail它来fail2ban给我发送通知。我读过多个关于如何设置的指南,但我无法让它工作。

我目前所做的:

  1. apt-get install sendmail
  2. 修改后/etc/hosts:“127.0.0.1 localhost”=>“127.0.0.1 localhost localhost.localdomain MYHOSTNAME”。我认为错误可能出在这里。由于我没有域名,所以 的输出hostname是错误的 IP 地址。因此,如果我的 IP 地址是1.2.3.4hostname则输出4-3-2-1。这就是我为“MYHOSTNAME”输入的内容。
  3. 重启
  4. sudo sendmailconfig

仍然sendmail没有发送并且/var/log/mail.log是空的。

输出var/log/syslog(所有大写字母均已被我修改):

Jan 17 11:58:11 MY-I-P-ADRESS sendmail[1814]: v0HBwBK4001814: from=fail2ban, size=100100, class=0, nrcpts=1, msgid=<[email protected]>, relay=root@localhost
Jan 17 11:58:11 MY-I-P-ADRESS sendmail[1814]: v0HBwBK4001814: [email protected], 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=<[email protected]>, 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=<[email protected]>, 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

答案1

当您输入时sudo sendmailconfig,系统应该提示您配置 sendmail。

作为参考,配置期间更新的文件位于以下位置(如果您想手动更新它们):

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

您可以通过在命令行中输入以下内容来测试 sendmail 以查看其是否已正确配置和设置:

$ echo "My test email being sent from sendmail" | /usr/sbin/sendmail [email protected]

以下命令可让您将 smtp 中继添加到 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

复制自sendmail:如何在 ubuntu 上配置 sendmail?在 Stack Overflow 上,回答者威尼斯,但修改为'将开头的引号改为`(该问题太旧,不适合迁移到这里。)

相关内容