Jamyy's Weblog

Postfix 以帳密驗證方式讓 relayhost 進行 Relay

by Jamyy on 八月.24, 2016, under Linux

在 Ubuntu 14.04.4 主機安裝並設置 Postfix
以帳號密碼驗證方式請遠端郵件主機轉寄郵件 (relay)

安裝並設定 Postfix

$ sudo su -
# apt install postfix libsasl2-modules
# cp /usr/share/postfix/main.cf.debian /etc/postfix/main.cf
# vi /etc/postfix/main.cf

myhostname=this.host.name
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_use_tls = yes
smtp_tls_security_level = encrypt
header_size_limit = 4096000
relayhost = [mail.server]:587
inet_interfaces = 127.0.0.1

# vi /etc/postfix/sasl_passwd

[mail.server]:587 myaccount:password

# postmap /etc/postfix/sasl_passwd
# chown postfix. /etc/postfix/sasl_passwd.db
# postfix reload
# exit

測試

$ telnet localhost 25

ehlo localhost
mail from: me@mail.server
rcpt to: myaccount@gmail.com
data
subject: this is a test
just a test
la la la
.
quit

以 mutt 寄送 HTML 內容的夾檔郵件

$ sudo apt install mutt
$ vi email.eml

<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
</head>
<body>
...
郵件內容
...
</body>
</html>

$ sudo mutt -e "set content_type=text/html" -s "郵件主旨" -a attachment.jpg -- user1@mail.server user2@mail.server < email.eml



後記:

  • 若 relay host 無 587 port, 可用 25 port
  • 若 relay host 想啟用 587 port, 且 relay host 是 postfix: 編輯 /etc/postfix/master.cf, 取消註解 submission 那行, 最後 postfix reload 就可以了



Ref:



: