OS:LINUX ubuntu server 9.10

1.下載postfix

apt-get install postfix

安裝時會問要那種type 選 internet site就可以了

host name預設本機名稱

使用 /etc/init.d/postfix restart 可以重啟postfix服務

dpkg-reconfigure postfix 可以重設

2.接下來安裝mailx 簡易的telnet收信軟體

apt-get install mailx

裝好後 打mailx 就會出現目前執行者有沒有新的信件

意指如果要架設mail server 關於使用帳密的架設 等於就是ubuntu使用者的建立

也就是ubuntu有個root 就會有root的信箱

3.接下來安裝pop與imap的服務 下面這個軟體是要與如outlook溝通用的

apt-get install dovecot-postfix

安裝好後編輯/etc/dovecot/dovecot-postfix.conf此檔 更改

protocols = imap pop3 imaps pop3s managesieve

disable_plaintext_auth=no

ssl_disable = no

ssl_cert_file = /etc/ssl/certs/ssl-mail.pem

ssl_key_file = /etc/ssl/private/ssl-mail.key

mail_location = mbox:~/mail:INBOX=/var/mail/%u

然後重啟服務

/etc/init.d/dovecot restart

接下來使用windows電腦之outlook設定

設定新信箱 帳密為ubuntu的使用者帳密 pop3與stmp皆為mail server的IP

皆著就可以測試 這個階段pop3正常就可以了

4.申請domain name

https://www.dyndns.com/

到上面的網址加入會員可以免費申請domain name

我申請為caramel.homelinux.net

如果IP有改也可以登入這個免費網站裡改 記得要把DNS指定為mail server

也可設成Mail Routing的MX record

MX hostname可以為caramel.homelinux.net 或是在申請一個DNS

可在http://www.mxtoolbox.com/ http://www.robtex.com/dns/ 裡查看

編輯/etc/hosts 加上

ISP的動態IP caramel.homelinux.net

5.還有一些額外的軟體要裝 下面這些軟體如有sasl的 是要寄外部信 與其它MTA做溝通用的 procmail則是篩信用的

apt-get install libsasl2-2 sasl2-bin libsasl2-modules db4.7-util procmail openssl

6.接下來進行profix的校正

關於postfix的設定主要在/etc/postfix/main.cf裡

我的設定為

smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
biff = no 

#信箱位置
mail_spool_directory = /var/mail

# appending .domain is the MUA's job.
append_dot_mydomain = no
# Uncomment the next line to generate "delayed mail" warnings
# delay_warning_time = 4h
#hostname為本機的名稱 也可以設為mail. caramel.homelinux.net不過DNS要申請就是了
myhostname = unbuntu

#domain就是剛申請的
mydomain = caramel.homelinux.net

mail_name = mailserver
#aliases可用來設定群組 也就是寄一個名字卻可以寄給這名字下屬的所有帳號 或幫一個帳號取別名
#記得要在這個檔案裡面加上root:/dev/null 這樣就不會都寄給root
#並要下指令postalias /etc/aliases 才會產生aliases.db檔 hash要讀db檔 不過寫時不加db喔
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases

#@後面要表示的
myorigin = $mydomain
#意思為寄信的目的地位址 如果是mydestination所指的 就是不外傳 代表是站內
mydestination = $mydomain, 192.168.1.4
#relayhost很重要 寄外部信 所依存的ISP mailserver
relayhost = $mydomain
relayhost = [168.95.4.10]
relayhost = [168.95.4.23]
relayhost = [ms23.hinet.net]
relayhost = [msa.hinet.net]

#通常動態IP server不給寄外部信 可以在/etc/postfix/isp_sasl_passwd加上自己的ISP帳密
#如isp_sasl_passwd的內容可為msa.hinet.net username:password
#記得要下指令postmap hash:/etc/postfix/isp_sasl_passwd 產生isp_sasl_passwd.db檔
smtp_sasl_password_maps = hash:/etc/postfix/isp_sasl_passwd
masquerade_domains = hinet.net
best_mx_transport = local

mynetworks_style = subnet
#這代表這台mailserver所屬的IP群組 與permit_mynetworks有關
mynetworks = 127.0.0.0/8, 192.168.1.0/24
recipient_delimiter = +
inet_interfaces = all
command_directory = /usr/sbin
daemon_directory = /usr/lib/postfix
program_directory = /usr/lib/postfix
config_directory = /etc/postfix 

#sasl setup
#關於sasl設定非常重要 這關係到信寄不寄得出去 
smtpd_sasl_auth_enable = yes
smtp_sasl_auth_enable = yes
smtpd_sasl_path = private/auth
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $mydomain

#smtpd_tls_wrappermode = no
smtpd_tls_auth_only = no
smtp_use_tls = yes
smtpd_use_tls = yes
smtp_tls_note_starttls_offer = yes
smtpd_tls_key_file = /etc/postfix/ssl/smtpd.key
smtpd_tls_cert_file = /etc/postfix/ssl/smtpd.crt
smtpd_tls_CAfile = /etc/postfix/ssl/cacert.pem
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
tls_random_source = dev:/dev/urandom
smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination
smtpd_client_restrictions = permit_sasl_authenticated
#outlook收信一定要打yes
broken_sasl_auth_clients = yes
mailbox_size_limit = 10240000
message_size_limit = 1240000

皆下來是/etc/postfix/master.cf的設定

smtp      inet  n       -      -       -       -       smtpd
smtps     inet  n       -       -       -       -       smtpd

7.進行ssl與smtpd設定

mkdir /etc/postfix/ssl
cd /etc/postfix/ssl/
openssl genrsa -des3 -rand /etc/hosts -out smtpd.key 1024
chmod 600 smtpd.key
openssl req -new -key smtpd.key -out smtpd.csr
openssl x509 -req -days 3650 -in smtpd.csr -signkey smtpd.key -out smtpd.crt
openssl rsa -in smtpd.key -out smtpd.key.unencrypted
mv -f smtpd.key.unencrypted smtpd.key
openssl req -new -x509 -extensions v3_ca -keyout cakey.pem -out cacert.pem -days 3650

8. Postfix 支援 Cyrus-SASL© V2 認証

修改/etc/default/saslauthd

START=yes

MECHANISMS="pam"

修改 /etc/postfix/sasl/smtpd.conf

echo 'pwcheck_method: saslauthd' >> /etc/postfix/sasl/smtpd.conf

echo 'mech_list: plain login' >> /etc/postfix/sasl/smtpd.conf

addgroup /etc/postfix sasl

測試saslauthd

/etc/init.d/saslauthd restart

testsaslauthd -u username -p password

啟動postfix

/etc/init.d/postfix restart

perl -MMIME::Base64 -e 'print encode_base64("0username\0password");'

會跑出一組亂碼 這時要複製記住

telnet 127.0.0.1 25

EHLO qemu HostName

會跑出這個mailserver支持的一些東西

皆著打

auth plain 複製的亂碼

看到235 Authentication successful 就代表sasl成功運作

不過我沒成功過也可以收寄信就是了

不過因為我用動態IP 如果那個IP已是黑名單 就怎麼寄都寄不到外面

不過如果是內部網路是沒有問題的

9.client端C:\windows\system32\drivers\etc\hosts

要加上192.168.1.X caramel.homelinux.net

也就是要在client的網路上說明這是內部的mailserver

10.如果信都塞在queue裡 可下指令

postsuper -r
postqueue -f

就可以送出

ps:smtp server 我都是用內部網域 如果用caramel.homelinux.net

又沒有作第九步的話 就會被網路上的 root DNS先擋掉了

也就是用內部網域把信丟給mail server 然後它在用relay host轉寄到外面去

arrow
arrow
    全站熱搜

    caramels 發表在 痞客邦 留言(0) 人氣()