发邮件时候遇到的一个问题

 发邮件的程序比较简单,在网上一搜一堆。我用的是自己架的postfix,基本都是默认配置,只改了发送权限的机器跟一些发送重试机制的参数。
但是在真正发邮件的时候,却遇到了一个令我比较郁闷的问题。找了几天也没有找到答案。我用的是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('test@g.com');
$smtp->to('test@g.com');
$smtp->data();
$smtp->datasend('From: test@g.com');
$smtp->datasend("/n");
$smtp->datasend('To: test@g.com');
$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。两种方案,根据实际情况选吧。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值