Mail Service On Ob2D

出自 新化國中wiki平台
前往: 導覽搜尋

SMTP:Postfix

apt-get install postfix

main.cf

  1. ref:
  2. 範例:
readme_directory = /usr/share/doc/packages/postfix/README_FILES
inet_protocols = all
biff = no
mail_spool_directory = /var/mail
canonical_maps = hash:/etc/postfix/canonical
virtual_alias_maps = hash:/etc/postfix/virtual
virtual_alias_domains = hash:/etc/postfix/virtual
relocated_maps = hash:/etc/postfix/relocated
transport_maps = hash:/etc/postfix/transport
sender_canonical_maps = hash:/etc/postfix/sender_canonical
masquerade_exceptions = root
masquerade_classes = envelope_sender, header_sender, header_recipient
myhostname = xxx.xxx.xxx <== 設定主機名稱
mydomain = xxx.xxx.xxx <== 設定 domain 名稱
program_directory = /usr/lib/postfix
inet_interfaces = all <== 要設成 all 才能使外部網路連進來
masquerade_domains =
mydestination = $mydomain, $myhostname <== 能夠收信的主機名稱
myorigin = $mydomain <== 就是寄信時顯示 “@” 之後的名稱
defer_transports =
mynetworks_style = subnet <== 設定信任網域,比較不重要
mynetworks = 127.0.0.0/8 <== 如果有設定這行會蓋掉上面那一行
disable_dns_lookups = no
relay_domains = <== 這一行就只要加自己的 domain 就可以了,不過我沒設定也沒影響
relayhost = <a href="http://msa.hinet.net/" target="_blank" title="http://msa.hinet.[">msa.hinet.net</a>] <== 因為如果我沒設定這行信都寄不出去,所以設定成 HINET 的信箱,這行要看自己 ISP 所給的信箱才能知道
mailbox_command = /usr/bin/procmail <== 這行是設定過濾信件用的軟體,不過我還沒設定
mailbox_transport =
strict_8bitmime = no
disable_mime_output_conversion = no
smtpd_sender_restrictions = hash:/etc/postfix/access
smtpd_client_restrictions =
smtpd_helo_required = no
smtpd_helo_restrictions =
strict_rfc821_envelopes = no
smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination
smtpd_client_restrictions = permit_sasl_authenticated <== 開啟 client 端認證</p>

smtp_sasl_auth_enable = no
smtpd_sasl_auth_enable = yes <== 開啟認證機制
smtpd_use_tls = no
smtp_use_tls = no
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
mailbox_size_limit = 0
message_size_limit = 10240000 <== 設定能夠寄送的郵件大小
smtpd_sasl_security_options = noanonymous <== 不接受匿名認證
broken_sasl_auth_clients = yes <== 設定這個才能使用 Outlook 5
header_checks = pcre:/etc/postfix/header_checks

master.cf

POP:pop3

SASL認證

安裝模組

apt-get install sasl2-bin libsasl2 libsasl2-modules

/etc/default/saslauthd

修改

START=yes

MECHANISMS="pam"

/etc/postfix/sasl/smtpd.conf

新增以下內容:

pwcheck_method: saslauthd
mech_list: login plain 

/etc/postfix/main.cf

smtpd_sasl_auth_enable = yes
broken_sasl_auth_clients = yes
smtpd_sasl_local_domain = $myhostname
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destinationi, check_relay_domains
smtpd_client_restrictions = permit_sasl_authenticated
smtpd_sasl_security_options = noanonymous

ln -s saslauthd

因為Postfix預設以chroot來啟動,導致saslauthd無法與Postfix溝通

所以做了以下設定,將原本saslauthd的執行資料夾link到以chroot啟動Postfix後的資料夾內,使saslauthd還是可以用自己預設的路徑來與Postfix溝通

 rm -r /var/run/saslauthd
 mkdir -p /var/spool/postfix/var/run/saslauthd
 ln -s /var/spool/postfix/var/run/saslauthd /var/run/saslauthd

addgroup postfix sasl

chgrp sasl /var/spool/postfix/var/run/saslauthd

adduser postfix sasl

RELOAD & TEST

/etc/init.d/postfix restart
/etc/init.d/saslauthd start
testsaslauthd -u username -p password

過濾病毒信:Amavisd-New

main.cf

content_filter = smtp-amavis:[127.0.0.1]:10024

master.cf

smtp-amavis unix -	-	n	-	2  smtp	# 設定為 n 表示不以 chroot 執行 postfix,在這裡的設定要和其它的 smtpd 之設定相同。
    -o smtp_data_done_timeout=1200			# 必須大於在 /etc/amavis/amavisd.conf 中的 $child_timeout 的值。
    -o smtp_send_xforward_command=yes			# 若使用 LMTP 時,則為 lmtp_send_xforward_command
    -o disable_dns_lookups=yes

127.0.0.1:10025 inet n	-	n	-	-  smtpd	# 在這裡的設定要和其它的 smtp 之設定相同。
    -o content_filter=						# 在這裡務必要清空,以免造成 Loop。
    -o local_recipient_maps=
    -o relay_recipient_maps=
    -o smtpd_restriction_classes=
    -o smtpd_client_restrictions=
    -o smtpd_helo_restrictions=
    -o smtpd_sender_restrictions=
    -o smtpd_recipient_restrictions=permit_mynetworks,reject
    -o mynetworks=127.0.0.0/8
    -o strict_rfc821_envelopes=yes
    -o smtpd_error_sleep_time=0
    -o smtpd_soft_error_limit=1001
    -o smtpd_hard_error_limit=1000
    -o receive_override_options=no_header_body_checks


SquirrelMail 中文處理的問題

  • SquirrelMail:郵件列表中文出現亂碼時,編輯 config/config.php:
$squirrelmail_default_language = ‘zh_TW’;
$default_charset = ‘big5′;
$lossy_encoding = false;
  • SquirrelMail:操作介面中文出現亂碼時,編輯 functions/i18n.php:
$languages[’zh_TW’][’NAME’] = ‘Chinese Trad’;
$languages[’zh_TW’][’CHARSET’] = ‘big5′;
$languages[’zh_TW’][’LOCALE’] = array(‘zh_TW.UTF-8′, ‘zh_TW.big5′);
$languages[’tw’][’ALIAS’] = ‘zh_TW’;
  • SquirrelMail:下載附件中文檔名亂碼,編輯 src/download.php:
$filename = charset_encode($filename,$default_charset,false); //在這行下面
$filename = iconv(“big5〃,”utf-8〃,$filename); //新增這一行

其他注意事項

  1. /tmp 屬性 應為777
  2. B2D Server 上的各種設定調校: http://b2ddoc.tnc.edu.tw/yh/LinuxBase/m7_security.html#mozTocId533873
  3. 如果有spamfilter,防火牆可設定是否直接交寄!
    • $IPTABLES -A INPUT -p tcp --dport 25 -j ACCEPT
    • or
    • $IPTABLES -A INPUT -p TCP -s ! 163.26.195.0/24 --dport 25 -j DROP
  1. 如果有spamfilter bind要設定一下 IN MX