需求: 今天遇到一个在内网安装的zabbix 由于不能通互联网,所以不能发报警邮件,需要解决把报警邮件发到外部邮件上。 解决方案: 找到一台能访问互联网又能通zabbix的主机安装nginx,进行邮件转发。

在zabbix编辑文件内容如下: vi /etc/mail.rc

This is the configuration file for Heirloom mailx (formerly

known under the name "nail".

See mailx(1) for further options.

This file is not overwritten when 'make install' is run in

the mailx build process again.

Sccsid @(#)nail.rc 2.11 (gritter) 8/2/08

Do not forward to mbox by default since this is likely to be

irritating for most users today.

set hold

Append rather than prepend when writing to mbox automatically.

This has no effect unless 'hold' is unset again.

set append

Ask for a message subject.

set ask

Assume a CRT-like terminal and invoke a pager.

set crt

Messages may be terminated by a dot.

set dot

Do not remove empty mail folders in the spool directory.

This may be relevant for privacy since other users could

otherwise create them with different permissions.

set keep

Do not remove empty private mail folders.

set emptybox

Quote the original message in replies by "> " as usual on the Internet.

set indentprefix="> "

Automatically quote the text of the message that is responded to.

set quote

Outgoing messages are sent in ISO-8859-1 if all their characters are

representable in it, otherwise in UTF-8.

set sendcharsets=iso-8859-1,utf-8

Display sender's real names in header summaries.

set showname

Display the recipients of messages sent by the user himself in

header summaries.

set showto

Automatically check for new messages at each prompt, but avoid polling

of IMAP servers or maildir folders.

set newmail=nopoll

If threaded mode is activated, automatically collapse thread.

set autocollapse

Mark messages that have been answered.

set markanswered

Hide some header fields which are uninteresting for most human readers.

ignore received in-reply-to message-id references ignore mime-version content-transfer-encoding

Only include selected header fields when forwarding messages.

fwdretain subject date from to

For Linux and BSD, this should be set.

set bsdcompat

set sendcharsets=iso-8859-1,utf-8 set from=发件人 set smtp=192.168.199.150 set smtp-auth-user=邮箱用户名 set smtp-auth-password=密码 set smtp-auth=login

编辑Nginx 配置文件如下:

For more information on configuration, see:

* Official English Documentation: http://nginx.org/en/docs/

* Official Russian Documentation: http://nginx.org/ru/docs/

worker_processes 1;

Load dynamic modules. See /usr/share/nginx/README.dynamic.

include /usr/share/nginx/modules/*.conf;

events { worker_connections 1024; }

stream { upstream mailsmtp_pro { server smtp.qiye.163.com:25; }

server { listen 25; proxy_connect_timeout 5s; proxy_timeout 5s; proxy_pass mailsmtp_pro; } }

http { log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"';

sendfile            on;
tcp_nopush          on;
tcp_nodelay         on;
keepalive_timeout   65;
types_hash_max_size 2048;

default_type        application/octet-stream;

include /etc/nginx/conf.d/*.conf;

server {

listen 8800; listen 443 ssl;

 location / {
	proxy_pass  https://qyapi.weixin.qq.com;

} } }

在zabbix 服务器上进行验证:

echo hello word | mail -s "zabbix ceshi" xxxx@126.com