在一台ubuntu18.04主机上查看sendmail为什么不能正常工作的问题。最近是换了服务器的域名。
网上的sendmail设置和实际情况不太符合。直接查看/etc/mail/下的配置文件,以前记得centos是直接改sendmail.cf或mailx的。

建议看这篇文章:
https://blog.csdn.net/yongren_z/article/details/85119088
https://blog.csdn.net/hongkaihua1987/article/details/108126113
如果没有mail.rc,可以重装。
yum install mailx
mail.rc的写法:

set smtp=smtps://smtp.xxx.com:465 # 这里填入smtp地址 set smtp-auth=login # 认证方式

set smtp-auth-user=user@xxx.com # 这里输入邮箱账号

set smtp-auth-password=password # 这里填入密码

set ssl-verify=ignore # 忽略证书警告

set nss-config-dir=/etc/pki/nssdb # 证书所在目录

set from=user@xxx.com # 设置发信人邮箱和昵称

set smtp-use-starttls=yes # STARTTLS时使用

此时可以使用mail发送邮件
cat [文件路径(邮件正文.txt)] | mail -s “[主题]” [收件地址]
echo “[正文内容]” | mail -s “[主题]” [收件地址]

如有中文乱码问题,可以尝试设置环境变量:
export LANG=”zh_CN.UTF-8”
export LC_ALL=”zh_CN.UTF-8”

报错:Error in certificate: Peer’s certificate issuer has been marked as not trusted by the.
创建证书,以qq为例

  1. mkdir -p /root/.certs/ ##先创建这个文件夹
  2. echo -n | openssl s_client -connect smtp.qq.com:465 | sed -ne '/-BEGIN
  3. CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/qq.crt
  4. certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
  5. certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
  6. certutil -L -d /root/.certs
  7. cd /root/.certs
  8. certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i qq.crt

https://blog.csdn.net/weixin_45346608/article/details/116119474

sendmai的配置文件修改:
sendmail.cf
,开头的备注清楚写明不能修改这里,要改改.mc。

DO NOT EDIT THIS FILE! Only edit the source .mc file.

sendmail.mc
,说明了改动后要生效需要执行其他命令:

If you modify this file, you will have to regenerate /etc/mail/sendmail.cf

by running this file through the m4 preprocessor via one of the following:

* make (or make -C /etc/mail)

* sendmailconfig

* m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf

The first two options are preferred as they will also update other files

that depend upon the contents of this file.

而且还有几项说明不要在这里改,要在conf文件改

DOMAIN(`debian-mta’)dnl

dnl # Items controlled by /etc/mail/sendmail.conf - DO NOT TOUCH HERE

undefine(`confHOST_STATUS_DIRECTORY’)dnl #DAEMON_HOSTSTATS=

dnl # Items controlled by /etc/mail/sendmail.conf - DO NOT TOUCH HERE

sendmail.conf
,然后这里是可以改的,改完也要执行命令:

After making changes here, you’ll need to run /usr/sbin/sendmailconfig

or /usr/share/sendmail/update_conf to have the changes take effect -

If you change DAEMON_MODE, QUEUE_MODE, or QUEUE_INTERVAL, you’ll also

need to run /etc/init.d/sendmail restart.

所有都指向了一个sendmailconfig,要想生效要执行这个。
检查了mail目录下,和原来域名相关的有好几个文件,(grep xxx.xxx.xxx -r )
源头应该是local-host-names ,vi修改了里面的域名。
执行sendmailconfig

midc@pha:/etc/mail$ sudo /usr/sbin/sendmailconfig

[sudo] password for midc:

Configure sendmail with the existing /etc/mail/sendmail.conf? [Y] y

Reading configuration from /etc/mail/sendmail.conf.

Validating configuration.

Writing configuration to /etc/mail/sendmail.conf.

Writing /etc/cron.d/sendmail.

Configure sendmail with the existing /etc/mail/sendmail.mc? [Y] y

Updating sendmail environment …

Reading configuration from /etc/mail/sendmail.conf.

Validating configuration.

Writing configuration to /etc/mail/sendmail.conf.

Writing /etc/cron.d/sendmail.

Reading configuration from /etc/mail/sendmail.conf.

Validating configuration.

Writing configuration to /etc/mail/sendmail.conf.

Writing /etc/cron.d/sendmail.

Could not open /etc/mail/databases(No such file or directory), creating it.

Reading configuration from /etc/mail/sendmail.conf.

Validating configuration.

Creating /etc/mail/databases…

Checking filesystem, this may take some time - it will not hang!

… Done.

Checking for installed MDAs…

sasl2-bin not installed, not configuring sendmail support.

To enable sendmail SASL2 support at a later date, invoke “/usr/share/sendmail/update_auth”

Creating/Updating SSL(for TLS) information

Creating /etc/mail/tls/starttls.m4…

You already have sendmail certificates

WARNING WARNING WARNING WARNING *

Everything you need to support STARTTLS (encrypted mail transmission

and user authentication via certificates) is installed and configured

but is NOT being used.

To enable sendmail to use STARTTLS, you need to:

1) Add this line to /etc/mail/sendmail.mc and optionally

to /etc/mail/submit.mc:

include(`/etc/mail/tls/starttls.m4’)dnl

2) Run sendmailconfig

3) Restart sendmail

Checking {sendmail,submit}.mc and related databases…

Reading configuration from /etc/mail/sendmail.conf.

Validating configuration.

Creating /etc/mail/databases…

Reading configuration from /etc/mail/sendmail.conf.

Validating configuration.

Creating /etc/mail/databases…

Reading configuration from /etc/mail/sendmail.conf.

Validating configuration.

Creating /etc/mail/Makefile…

Reading configuration from /etc/mail/sendmail.conf.

Validating configuration.

Writing configuration to /etc/mail/sendmail.conf.

Writing /etc/cron.d/sendmail.

Disabling HOST statistics file(/var/lib/sendmail/host_status).

Creating /etc/mail/sendmail.cf…

Creating /etc/mail/submit.cf…

Informational: confCR_FILE file empty: /etc/mail/relay-domains

Informational: confCT_FILE file empty: /etc/mail/trusted-users

Updating /etc/mail/access…

Informational: ALIAS_FILE file empty: /etc/mail/aliases

Updating /etc/mail/aliases…

/etc/mail/aliases: 0 aliases, longest 0 bytes, 0 bytes total

Reload the running sendmail now with the new configuration? [Y] y

Reloading sendmail …

再次检查相关文件的域名部分已经被修改了