但是在真正發郵件的時候,卻遇到了一個令我比較鬱悶的問題。找了幾天也沒有找到答案。我用的是Net::Smtp模塊發送的,起初我懷疑是沒有用好。之後又懷疑一次的tcp連接太多等等,總之,問題沒有解決。
無奈之下,我到postfix官網上找到了Kyle Dent的聯繫方式。 (之前熟悉postfix也是看他寫得那本書)
我去信請教的大概內容:
Hi kdent,
I get some puzzled problem when i use PostFix.
My program snatched some email list( About 30,000). Then i use my Postfix to send email.
You know,to reduce connection times,I ONLY set up ONEC time connection to Postfix.
That is to say,I did it as following step:
<mockcode>
1) connect the PostFix.
2) call the mail function in loop.
3) quit the connect.
</mockcode>
After ran the program(The program spent 20s or so),i check the postfix log (/var/log/maillog/) ,Only about 1,000 lists have been sent.
Remainder lists didn't been recorded any info.
Do I need some special config for this aim?
BTW,My postconf is :
。。。
兩天之後,kyle給我了答覆:
You should take a look at the smtpd limit configuration parameters. They
are all named starting with smtpd and end in limit (smtpd_*_limit). No
doubt you're running into one of those. Also Postfix will report to your
client the reason for not accepting a message. Be sure to check the
response from Postfix to see if a message was accepted or not. If not
then check the error message for the reason.
按圖索驥,我又找了一下postfix的配置 ,最終將問題定位在 smptd_recipient_limit 這個參數上。其默認值是1000。
我的代碼:
sug smail {
###(1)$smtp = Net::SMTP->new('xx.xx.xx.xx');
$smtp->mail('[email protected]');
$smtp->to('[email protected]');
$smtp->data();
$smtp->datasend('From: [email protected]');
$smtp->datasend("/n");
$smtp->datasend('To: [email protected]');
$smtp->datasend("/n");
$smtp->datasend('Content-type:text/html;Charset=gb2312');
$smtp->datasend("/n");
$smtp->datasend("Subject: test!");
$smtp->datasend("/n/n");
$smtp->datasend("<b>how are you!</b>/n");
$smtp->dataend();
$smtp->dataend();
###(2) $smtp->quit;
}
如此一來,只要將smptd_recipient_limit 調大,把註釋1,2放到發送郵件的外部,就可以只建立一次NET socket,然後不停的發送郵件了。
當然去掉註釋1,2其邏輯就是每發一封郵件,就new一個Net::SMTP。兩種方案,根據實際情況選吧。