找回密码
 立即注册
搜索
查看: 345|回复: 0

Linux 邮件

[复制链接]

266

主题

0

回帖

1119

积分

管理员

积分
1119
发表于 2024-1-26 00:04:38 | 显示全部楼层 |阅读模式

mail

mail 是 mailx 的软连接,它相当于邮箱客户端(例如 foxmail 客户端),可以单独使用通过 smtp 发送邮件或查看邮箱(/var/spool/mail/[用户名])中的邮件。单独使用 mail 发邮件需要配置 smtp:

/etc/mail.rc

set from=xxx@163.com
set smtp=smtp.163.com
set smtp-auth-user=xxx@163.com
set smtp-auth-password=***
set smtp-auth=login

发邮件测试:

echo "test" |mail -v -s "subjuct" xxx@qq.com

-v:显示发送过程

公司使用的是阿里的企业邮箱,感觉不稳定(可能是被某种策略过滤),有时候发送会出错:

SMTP: Connection reset by peer
Unexpected EOF on SMTP connection

换成 163 邮箱测试就很稳定。

查阅邮件:mail

d* #删除所有邮件

d n #删除编号n的邮件

sendmail/postfix

sendmail/postfix 则是邮件服务器程序,类似 163、qq 邮箱。

配置 postfix 使用代理 stmp 发送邮件:

vim /etc/postfix/main.cf

# Enable auth
smtp_sasl_auth_enable = yes
# Set username and password
smtp_sasl_password_maps = static:gitlab@example.com:passwordstring
smtp_sasl_security_options = noanonymous
smtp_tls_security_level = encrypt
smtp_tls_wrappermode = yes
relayhost = [smtp.qiye.aliyun.com]:465

systemctl restart postfix

这样 cron 就可以通过 postfix 发送邮件了。没有 postfix 时 cron 不会通过 mail.rc 配置的 stmp 发送邮件的。

在已经配好 postfix 时可以不用通过配 mail.rc 来使用 mailx 发信了测试命令如下:

echo "test" |mailx -v -s "subjuct" -r "gitlab@example.com(Gitlab)" xxx@qq.com

需要注意的是必须包括发件人(用 -r 定义的(可以只写邮箱 -r gitlab@example.com),且必须与 smtp 代理的账户是一致的(通常邮件服务器都是这样要求的)),否则会提示错误:

440 mail from account doesn't conform with authentication (Auth Account:gitlab@example.com|Mail Account:root@gitserver.localdomain) (in reply to MAIL FROM command)

怀疑 cron 不是使用 mailx 发邮件的,而是直接通过 sendmail/postfix 来发的。

crontab 的配置开头除了 MAILTO="xxx@qq.com" 还要有 MAILFROM="gitlab@example.com",否则邮件不能被正常发送。

vim /var/spool/cron/root

MAILTO="xxx@qq.com"
MAILFROM="gitlab@example.com"
*/10 * * * * /root/script/backup-svn-authz.sh
0 2 * * * /root/script/backup-svn-gitlab.sh
0 6 1 * * /root/script/backup-svn-monthly.sh
postfix 小于 3.0 的版本不支持 465 加密端口,需要注意。

CentOS 7 安装 postfix 3

查看版本:

postconf -d | grep mail_version
mail_version = 2.10.1
milter_macro_v = $mail_name $mail_version

或
rpm -qa | grep postfix
postfix-2.10.1-9.el7.x86_64

删除 postfix 2:

yum remove postfix           

添加 postfix 3 源:

vim /etc/yum.repos.d/gf.repo

[gf]
name=Ghettoforge packages that won't overwrite core distro packages.
mirrorlist=http://mirrorlist.ghettoforge.org/el/7/gf/$basearch/mirrorlist
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-gf.el7
failovermethod=priority

[gf-plus]
name=Ghettoforge packages that will overwrite core distro packages.
mirrorlist=http://mirrorlist.ghettoforge.org/el/7/plus/$basearch/mirrorlist
# Please read http://ghettoforge.org/index.php/Usage *before* enabling this repository!
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-gf.el7
failovermethod=priority

安装 postfix 3:

yum install postfix3

重新配置后就可以启动了。


您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|棱讯科技 ( 粤ICP备2024228160号-2|粤公网安备44030002003510号 )

GMT+8, 2024-7-27 23:09 , Processed in 0.016278 second(s), 3 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表