跳至主要內容

邮件配置

知识库天信瑞安云盘服务云盘服务小于 1 分钟

测试邮件

## 安装依赖
yum install -y sendemail mailx
## 发送测试邮件
sendemail -f dev@bjtxra.com -t zhanghaijun@bjtxra.com -s smtp.exmail.qq.com:587 -xu dev@bjtxra.com -xp 'Bedrock123!@#' -u "Test Email" -m "This is a test email."

Postfix

配置

yum install postfix cyrus-sasl-plain

smtp_host=smtp.exmail.qq.com
smtp_user=dev@bjtxra.com
smtp_password='Bedrock123!@#'
from_user=dev@bjtxra.com
admin_email=monitor@alot.pw

sed -i "s/inet_protocols = all/inet_protocols = ipv4/g" /etc/postfix/main.cf
cat  >>  /etc/postfix/main.cf <<EOF
relayhost = [$smtp_host]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options =
smtp_use_tls = yes
smtp_tls_CApath = /etc/ssl/certs
sender_canonical_classes = envelope_sender, header_sender
sender_canonical_maps =  regexp:/etc/postfix/sender_canonical_maps
smtp_header_checks = regexp:/etc/postfix/header_checks
EOF
cat  >>  /etc/postfix/sasl_passwd <<EOF
[$smtp_host]:587 $smtp_user:$smtp_password
EOF
chmod 600 /etc/postfix/sasl_passwd
postmap /etc/postfix/sasl_passwd

cat >> /etc/postfix/sender_canonical_maps <<EOF
/.+/    $from_user
EOF
postmap /etc/postfix/sender_canonical_maps

cat >> /etc/postfix/header_checks <<EOF
/From:.*/ REPLACE From: $from_user
EOF

cat >> /etc/aliases <<EOF
root:           $admin_email
EOF

## 重启服务
systemctl restart postfix && systemctl status postfix

测试

## 查看邮件队列
mailq
## 清空邮件队列
systemctl stop postfix && postsuper -d ALL && systemctl start postfix && systemctl status postfix

## 测试发送邮件
echo "This is a test email" | sendmail zhanghaijun@bjtxra.com
echo "This is a test email" | mail -s "test" zhanghaijun@bjtxra.com