目录



1、背景

服务器名

IP

网络环境

ng

10.22.86.3

DMZ区

mail

10.22.86.3

内网

mail服务器无法访问外网

nginx正向代理,在ng主机上配置nginx正向代理服务,主机mail邮件服务器目的地址只需要填写ng的地址即可通过ng主机代理发邮件。

2、ng主机安装nginx

// 安装包版本需要在1.10.0以上
wget http://nginx.org/download/nginx-1.18.0.tar.gz
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
//安装依赖
yum install -y pcre-devel
//创建用户
useradd -M -s /sbin/nologin nginx
tar -zxvf nginx-1.18.0.tar.gz -C /usr/local/
cd /usr/local/nginx-1.18.0
// 安装时一定要编译上 mail 和 stream
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-mail --with-stream --with-http_stub_status_module --with-http_ssl_module
make && make install


3、安装完成修改主配文件

cd /usr/local/nginx/conf
cat nginx.conf.default | grep -v '#\|^$' > nginx.conf
vim /usr/local/nginx/conf/nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
stream{
server {
listen 8025;
proxy_pass smtp.163.com:25;
}
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}


4、启动

/usr/local/nginx/sbin/nginx


5、mail主机配置

yum install mailx -y
vim /etc/mail.rc
// 在行添加内容
set bsdcompat
set sendcharsets=iso-8859-1,utf-8
// 发件邮箱
set from=m151****0025@163.com
// nginx地址,若有外网可以直接填写邮箱地址
set smtp=10.22.86.3:8025
set smtp-auth-user=m151****0025@163.com
set smtp-auth-password=DGPZ********DJCRA
set smtp-auth=login


6、测试发送邮件

echo "zabbix test mail" | mailx -v -s "zabbix" 139******22@qq.com


  • 结果:
Resolving host 10.22.86.3 . . . done.
Connecting to 10.22.86.3:8025 . . . connected.
220 163.com Anti-spam GT for Coremail System (163com[20141201])
>>> EHLO localhost
250-mail
250-PIPELINING
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250-coremail 1Uxr2xKj7kG0xkI17xGrU7I0s8FY2U3Uj8Cz28x1UUUUU7Ic2I0Y2UFMTtxdUCa0xDrUUUUj
250-STARTTLS
250 8BITMIME
>>> AUTH LOGIN
334 dXNlcm5hbWU6
>>> bTE1MTA3MjEwMDI1QDE2My5jb20=
334 UGFzc3dvcmQ6
>>> REdQWlFGS0dKSlJESkNSQQ==
235 Authentication successful
>>> MAIL FROM:<m151*****25@163.com>
250 Mail OK
>>> RCPT TO:<13*****22@qq.com>
250 Mail OK
>>> DATA
354 End data with <CR><LF>.<CR><LF>
>>> .
250 Mail OK queued as smtp14,EsCowAAXhOmJPnph+FmoIA--.34144S2 1635401354
>>> QUIT
221 Bye