2010/06/16

Setting Random Times with zope.sendmail

This is an abstract from How to add a random time between two emails sent from zope.sendmail.

需要搭配 Plone 架設 newsletter 的場合,可以使用 collective.dancing,它能夠管理訂戶資料,並利用 zope.sendmail 協助自動發信。如果訂戶數量過大,批次發信可能會被列入黑名單,此時,試試設定亂數時點,來處理這樣的問題。方式是撰寫 plone.smtp 程式碼:
import random
import time

from zope.sendmail import mailer

class SMTP(mailer.SMTPMailer):
"""Override SMTPMailer to let a random time"""

def send(self, fromaddr, toaddrs, message):
time.sleep(random.uniform(0,2))
super(SMTP, self).send(fromaddr, toaddrs, message)

No comments: