顯示具有 postfix 標籤的文章。 顯示所有文章
顯示具有 postfix 標籤的文章。 顯示所有文章

2025/10/15

昨天有人說群組信都寄不出去
我覺得奇怪 程式跟 mail server最新都沒改設定
而且之前也都沒問題
問了才知道user一定選了40個群組
查看log 發現出現一堆







最後出現







之前的設定是





因為發信程式會先送一封 
group.mail.abc.com.tw
過來
所以要能收進來然後 mail server會丟掉 如上圖

但現在狀況是當user一次選了太多群組
會產生很多 error 然後觸發 disconnect 几制

因此改用另一種方法

先把 mydestination 裡的 group.mail.abc.com.tw 刪除

在transport進行判斷
設定 /etc/postfix/main.cf  
加上一行:

transport_maps = hash:/etc/postfix/transport

把寄到 group.mail.abc.com.tw 的信丟掉
建立/etc/postfix/transport檔案,加上一行: 
group.mail.abc.com.tw discard:

執行 postmap 編碼

postmap  /etc/postfix/transport

重啟 postfix

後記 

昨天有試著使用 header_checks 但沒解決
應該沒几個人用一樣的發信程式吧

2023/04/14

為了因應centos 7 EOS

今天在轉移程式到 almalinux 9 時 mutt 一直無法寄信

mail server 的log如下

Apr 14 10:09:09 mail postfix/smtpd[523701]: connect from unknown[10.0.0.1]

Apr 14 10:09:09 mail postfix/smtpd[523701]: lost connection after STARTTLS from unknown[10.0.0.1]

看來almalinux 9的mutt 預設會使用 STARTTLS

在 .muttrc 加上以下這行

set ssl_force_tls = no


目前寄信正常了


20240308 後記


轉換到新mail server後 有些mutt又出現不能寄信的狀況

以下是log


Mar  8 06:13:01 mail postfix/smtpd[27212]: warning: TLS library problem: error:0A000126:SSL routines::unexpected eof while reading:ssl/record/rec_layer_s3.c:320:

Mar  8 06:13:01 mail postfix/smtpd[27212]: lost connection after STARTTLS from unknown[10.0.0.1]


必須在.muttrc再加上 set ssl_starttls = no 
包括之前說明的共二行如下

set ssl_force_tls = no
set ssl_starttls = no

目前正常了 再觀察看看

2023/01/07

在一台几器上使用mutt寄信時出現

SMTP session failed: 502 5.5.2 Error: command not recognized


到mail server上看log


Jan  7 05:39:01 mail postfix/smtpd[1874477]: improper command pipelining after EHLO from unknown[10.0.01]: hostabc\r\n

感覺好像是hostname的問題

於是在 .muttrc 裡加上一行

set hostname=myhost


就ok了

2019/10/21

proxmox mail gateway

預設不會去記錄信件主旨
因此要查找的時候有些不方便
修改方法如下

在 /etc/postfix/main.cf最後增加一行如下

header_checks = regexp:/etc/postfix/header_checks

建立 /etc/postfix/header_checks 這個檔 內容如下

/^Subject:/      WARN

接下來重啟服務
systemctl restart postfix

之後就可以在 /var/log/mail.log看到如下的log

Oct 21 06:43:49 mg postfix/cleanup[19866]: 74A29109C: warning: header Subject: Congratulate Jimmy (Gin-der) Peng for... from mailc-ab.linkedin.com[108.174.3.162]; from=<s-2f4oc1y30l5mpjzdxdjdkon8civu58akgxu9lf1h23ha66tmdhfi46d4@bounce.linkedin.com> to=<abc@de.com> proto=ESMTP helo=<mailc-ab.linkedin.com>

以上的方法在几器重開後 config就會被改回來

找到另一個方法
直接去改pmg的perl

First, add this somewhere between the 'use' statements at the beginning of the file:

use PVE::Tools;

Then search for this line:

$self->log (3, "$queue->{logid}: new mail message-id=%s", $queue->{msgid});

Add the following below that line:

$self->log (3, "$queue->{logid}: Subject: %s", PMG::Utils::decode_rfc1522(PVE::Tools::trim($entity->head->get('subject'))) || 'No Subject');
my @fromarray = split('\s*,\s*', $entity->head->get('from') || $msginfo->{sender});
$self->log (3, "$queue->{logid}: From: %s", PMG::Utils::decode_rfc1522(PVE::Tools::trim($fromarray[0])) );

https://forum.proxmox.com/threads/how-to-log-subjects-of-all-incoming-email.54191/

第二種方法會把subject放在獨立行
不方便查找

官方其實有提供解法方法

You can find the default templates in /var/lib/pmg/templates/. Please do not modify them directly, because your modification would get lost on the next update. Instead, copy the template you wish to change to /etc/pmg/templates/, then apply your changes there.

Templates can access any configuration setting, and you can use the pmgconfig dump command to get a list of all variable names:

# pmgconfig dump
...
dns.domain = yourdomain.tld
dns.hostname = pmg
ipconfig.int_ip = 192.168.2.127
pmg.admin.advfilter = 1
...
The same tool is used to force regeneration of all template based configuration files. You need to run that after modifying a template, or when you directly edit configuration files

# pmgconfig sync --restart 1

https://pmg.proxmox.com/pmg-docs/pmg-admin-guide.html#_service_configuration_templates

2019/10/11

一樣是升級centos 8 postfix 後的問題
這次希望能有判別spam的功能
請出老牌的 spamassassin
網路上的很多文章都提到與mailscanner 或 amavisd-new 整合
但我希望能直接用postfix
做法如下

dnf install spamassassin

好在有放進list可以直接用

加group跟user

groupadd spamd

useradd -g spamd -s /bin/false -d /var/log/spamassassin spamd

改權限
chown spamd:spamd /var/log/spamassassin

再來修改 /etc/postfix/master.cf

找到 
smtp      inet  n       -       n       -       -       smtpd

改成
smtp      inet  n       -       n       -       -       smtpd -o content_filter=spamassassin

在最後加上
spamassassin unix - n n - - pipe flags=R user=spamd argv=/usr/bin/spamc -e /usr/sbin/sendmail -oi -f ${sender} ${recipient}

systemctl restart spamassassin
systemctl restart postfix
systemctl enable spamassassin

更新rule
sa-update -D --nogpg

會出現有缺東西的情況 能補就補
最後有二個dnf也沒法補
目前是不影響功能

Oct 11 07:36:44.595 [24809] dbg: diag: [...] module not installed: Net::Patricia ('require' failed)
Oct 11 07:36:44.595 [24809] dbg: diag: [...] module not installed: Net::DNS::Nameserver ('require' failed)

寫個crontab定時做
1 7,19 * * * /usr/bin/sa-update -D --nogpg;/usr/bin/systemctl restart spamassassin

如果想要能夠學習
建 whitelist , blacklist 二個user 分別把誤判及未判的信轉過去

然後再寫個crontab定時做

#!/bin/bash

/usr/bin/sa-learn --no-sync --ham /home/whitelist/Maildir/{cur,new}
rm -rf /home/whitelist/Maildir/*

/usr/bin/sa-learn --no-sync --spam /home/blacklist/Maildir/{cur,new}
rm -rf /home/blacklist/Maildir/*


2019/10/05

最近把mail server升到 centos 8
可是
預設卻找不到 postgrey
XD

只好手動來了
首先到 https://postgrey.schweikert.ch/ 下載
直接解開就可以用了 不用編譯
只是要補一些東西

dnf install -y perl-NetAddr-IP perl-Net-Server perl-BerkeleyDB

groupadd nogroup
adduser postgrey

mkdir /var/spool/postfix/postgrey
touch /var/spool/postfix/postgrey/socket
chown -R postgrey.nogroup /var/spool/postfix/postgrey

cd /etc/postfix

下載官方白名單
wget https://postgrey.schweikert.ch/pub/postgrey_whitelist_clients

再產生一個 /etc/postfix/postgrey_whitelist_recipients 視需要修改內容

啟動postgrey

./postgrey --unix=/var/spool/postfix/postgrey/socket --delay=60 -d

記得加入 /etc/rc.local開几執行

修改 /etc/postfix/main.cf

在原來的
smtpd_recipient_restrictions =
加上
   check_policy_service unix:/var/spool/postfix/postgrey/socket

重啟postfix
systemctl restart postfix

接下來看看/var/log/maillog 有沒有類似以下的訊息
如果有
就表示ok了

Oct  5 11:21:57 mail postfix/smtpd[10103]: NOQUEUE: reject: RCPT from nedm.ubot.com.tw[125.227.165.70]: 450 4.2.0 <abc@test.com>: Recipient address rejected: Greylisted, see http://postgrey.schweikert.ch/help/mail.nkuht.edu.tw.html; from=<UBOT@nedm.ubot.com.tw> to=<shangpao@mail.nkuht.edu.tw> proto=ESMTP helo=<nedm.ubot.com.tw>

postgrey有一個報表工具 postgreyreport
如果要使用要再補上

dnf install -y perl-Net-DNS

指令如下

Depending on how busy your server is, the report can get quite large. To get only the top 20 sources getting greylisted out - you can use something like this :

cat /var/log/maillog | postgreyreport | awk '{print $1}' | sort | uniq -c | sort -nr | head -n20

To get a list of the top 20 email address that the greylisted sources are sending email to :

cat /var/log/maillog | postgreyreport | awk '{print $4}'  | sort  | uniq -c | sort -nr | head -n20


https://wiki.centos.org/HowTos/postgrey#head-70ed10e62fb7da94deb39a987e1e4e205c2ae2c5

2015/06/26

好像愈來愈多人設定forword來把信轉到gmail去
導致因為信件量太多而被google擋了
一直出現

Jun 26 13:43:11 mail postfix/smtp[19923]: 4BB3B9E0624: lost connection with ALT1.ASPMX.L.GOOGLE.COM[64.233.168.26] while receiving the initial server greeting
Jun 26 13:43:13 mail postfix/smtp[19922]: 743E79E058A: lost connection with alt2.gmail-smtp-in.l.google.com[64.233.168.27] while receiving the initial server greeting

除了要求user不要再轉信而用pop3來收信外
想不出來有什麼方式可以解決了

查了一下google有提供轉發的服務
https://support.google.com/a/answer/2956491?hl=zh-Hant

再想看看要不要用

2015/05/08

在 mail server的log裡發現

postfix/smtp[1921]: 347A79E0739: to=<abc@gmail.com>, orig_to=<abc@bbb.edu.tw>, relay=alt1.gmail-smtp-in.l.google.com[74.125.25.27]:25, delay=239783, delays=239779/0.04/2.6/0.84, dsn=4.7.0, status=deferred (host alt1.gmail-smtp-in.l.google.com[74.125.25.27] said: 421-4.7.0 [2.3.4.5      15] Our system has detected an unusual rate of 421-4.7.0 unsolicited mail originating from your IP address. To protect our 421-4.7.0 users from spam, mail sent from your IP address has been temporarily 421-4.7.0 rate limited. Please visit 421-4.7.0 http://www.google.com/mail/help/bulk_mail.html to review our Bulk 421 4.7.0 Email Senders Guidelines. d5si4976585pdi.47 - gsmtp (in reply to end of DATA command))

被google擋信了
查了一下google的網頁說明
有三個方式可以處理
最方便的是在DNS設定spf

;spf for google
bbb.edu.tw.  3600  IN   TXT   "v=spf1 ip4:2.3.4.5 include:_spf.google.com ~all"

設定後重啟DNS
等cache更新後就ok了

2014/05/15

今天又有user反應校外不能寄信的問題
參考了一下這篇
設定完成後
不管校內校外都不能發信了
看了一下log
fatal: no SASL authentication mechanisms
warning: xsasl_cyrus_server_get_mechanism_list: no applicable SASL mechanisms

參考以下連結
http://www.electrictoolbox.com/postfix-smtp-auth-no-sasl-authentication-mechanisms/

發現還要裝上 cyrus-sasl-plain 才能用

yum install cyrus-sasl-plain

2014/01/21

postfix如果要利用header_checks來check中文是會有問題的
必須先把中文進行編碼
網址如下
http://www.mytju.com/classCode/tools/base64.asp
要分utf8或big5

編出來之後再加入header_checks
/^Subject:.*5biQ5oi3/ DISCARD
/^Subject:.*pc6k4Q==/ DISCARD

postfix要重啟

2013/08/26

早上有人反應webmail打不開
查了一下log
發現如下的情況

Aug 26 09:44:09 mail dovecot: master: Warning: service(imap): process_limit reached, client connections are being dropped
Aug 26 09:45:20 mail dovecot: master: Warning: service(imap): process_limit reached, client connections are being dropped
Aug 26 09:46:25 mail dovecot: master: Warning: service(imap): process_limit reached, client connections are being dropped
Aug 26 09:49:32 mail dovecot: master: Warning: service(imap): process_limit reached, client connections are being dropped

imap 超過預設值了

修改/etc/dovecot/conf.d/10-master.conf
#default_process_limit = 100
default_process_limit = 2000
#default_client_limit = 1000
default_client_limit = 4003

service auth {
加上
client_limit=6048
}

dovecot restart後再觀察看看
dovecot restart時如果預設值有問題
會顯示應該調整的參數

升到centos 6 後不管是postfix或是dovecot 預設值都滿低的
只能夠碰到問題再來慢慢調整了


2013/08/15

轉換到新mail server時發生用webmail走imap登入時無法出現資料夾的情況
查了一下log發現新版本的dovecot 有限制user+IP的連線數量
預設為10
log如下
Aug 11 20:49:07 mail dovecot: imap-login: Maximum number of connections from user+IP exceeded (mail_max_userip_connections=10): user=<test>, method=PLAIN, rip=1.1.1.1, lip=2.2.2.2
查了一下文件
先在/etc/dovecot/dovecot.conf加上
mail_max_userip_connections = 200

後正常
再觀察看看