使用nginx轉發sendmail實現發郵件

需求:
今天遇到一個在內網安裝的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" [email protected]

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章