Web、Mail、Ftp、DNS、Proxy、VPN、Samba、LDAP 等基础网络服务
-
ouleiqi
- 帖子: 16
- 注册时间: 2021-11-24 10:22
- 系统: UbuntuLTS 20.04
#1
帖子
由 ouleiqi » 2021-11-24 10:31
问题:
单独测试ssmtp 发送邮件,总是成功。
crontab 定时每天,用logWatch 发送邮件,有时成功,有时失败。
怀疑是 crontab的问题。
直接用root执行 /etc/cron.daily/00logwatch 脚本。 发现有时发送过去,有时发送不出去。
相关信息如下:
代码: 全选
root@yxhserver:~# /etc/cron.daily/00logwatch
sendmail: Cannot open smtp.163.com:465
root@yxhserver:~# /etc/cron.daily/00logwatch
sendmail: Cannot open smtp.163.com:465
root@yxhserver:~# /etc/cron.daily/00logwatch
sendmail: Cannot open smtp.163.com:465
root@yxhserver:~# /etc/cron.daily/00logwatch # 这里执行成功了
root@yxhserver:~#
logwatch 内容如下:
代码: 全选
#!/bin/bash
#!/bin/bash
#Check if removed-but-not-purged
test -x /usr/share/logwatch/scripts/logwatch.pl || exit 0
#execute
#/usr/sbin/logwatch --output mail
/usr/sbin/logwatch --range Yesterday --mailto myemail
#Note: It's possible to force the recipient in above command
#Just pass --mailto address@a.com instead of --output mail
sstmp 权限如下:
代码: 全选
-rw-r----- 1 root mail 278 Mar 30 2021 revaliases
-rw-r----- 1 root mail 669 Mar 30 2021 ssmtp.conf
请大神帮忙看下,哪里可能出问题了?
-
astolia
- 论坛版主
- 帖子: 6514
- 注册时间: 2008-09-18 13:11
#2
帖子
由 astolia » 2021-11-24 14:49
报的错是无法连接到smtp.163.com:465,那要么是ssmtp的设置问题,要么是你的网络环境问题。你的ssmtp.conf里面是怎么配置的?
-
ouleiqi
- 帖子: 16
- 注册时间: 2021-11-24 10:22
- 系统: UbuntuLTS 20.04
#3
帖子
由 ouleiqi » 2021-11-24 14:57
谢谢 astolia 的答复
ssmtp.conf 配置如下:
代码: 全选
mailhub=smtp.163.com:465
hostname=smtp.163.com:465
AuthUser=ou.leiqi@163.com
AuthPass=myauthpass
UseTLS=YES
使用mail、sendmail、每次均能收到邮件。 只有在 logwatch 时才【经常】出现如下错误。
代码: 全选
sendmail: Cannot open smtp.163.com:465
特别奇怪
-
ouleiqi
- 帖子: 16
- 注册时间: 2021-11-24 10:22
- 系统: UbuntuLTS 20.04
#4
帖子
由 ouleiqi » 2021-11-24 17:40
应该是ipv4/ipv6的问题导致的, 我的电脑支持ipv4、ipv6; 但是网易的smtp仅支持ipv4; 所以导致有时发送成功有时失败。
然后修改 logwatch.conf 改成强制 ipv4(查找ssmtp配置发现支持-4、-6参数)如下:
代码: 全选
# TODO test variables in the mailer string to see if the To/From/Subject can be set
# From here with out breaking anything. This would allow mail/mailx/nail etc..... -mgt
#mailer = "/usr/sbin/sendmail -t"
mailer = "/usr/sbin/sendmail -4"
但是依旧不起作用,看作者的注释,好像没有测这个传递参数的功能。 这个怎么解决呢?
-
ouleiqi
- 帖子: 16
- 注册时间: 2021-11-24 10:22
- 系统: UbuntuLTS 20.04
#5
帖子
由 ouleiqi » 2021-11-25 10:00
已解决:
传递强制ipv4的参数后,第二天重启了下系统;一直发送成功了。
代码: 全选
mailer = "/usr/sbin/sendmail -4"
神奇的重启大法;