在 Ubuntu 9.04 使用 svk 出現 Can’t locate Time/Progress.pm

在公司正想用 svk 把 monodevelop source code 拉回來時,發現有 Can’t locate Time/Progress.pm 訊息,然後就停止運行了。
Launchpad 找了一下,發現已經有人回報了:Bug #317487 in svk (Ubuntu): “2.2.1 needs Time::Progress”,後續的回覆裡,也提供了好幾個 workaround,我選擇直接修改 Notify.pm,因為以後 apt-get upgrade 時,新檔案會把舊檔案覆蓋掉。

python twisted sendmail

buildbot 是用 twisted library 裡的 sendmail 寄信的,方法如下:

from email.Message import Message
from twisted.mail.smtp import sendmail
from twisted.internet import defer
from twisted.internet import reactor
m = Message()
m.set_payload("Hello world!!")
m['To']="someone@somewhere.com"
m['Subject'] = "Test"
m['From'] = "my@somewhere.com"
s = m.as_string()
done = sendmail( "mailserver", "my@somewhere.com", [ "someone@somewhere.com" ], s)
done.addCallback(lambda ignored: reactor.stop())
reactor.run()

但現在大多的 mail server 都需要先認證,這時候就得改用 ESMTPSenderFactory 來改寫了(可參考Twisted mail smtp API),mailing list 裡正好有人貼出程式

from twisted.mail import smtp
from twisted.internet import reactor
from twisted.internet import defer
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
def sendmail_auth(smtphost, user, password,
from_addr, to_addrs, msg, senderDomainName=None, port=25):
if not hasattr(msg,'read'):
msg = StringIO(str(msg))
d = defer.Deferred()
factory = smtp.ESMTPSenderFactory(user, password, from_addr, to_addrs, msg, d,
requireTransportSecurity=False)
if senderDomainName is not None:
factory.domain = senderDomainName
reactor.connectTCP(smtphost, port, factory)
return d

再套前面的例子,只要改動 sendmail 為 sendmail_auth 就行了:程式

done = sendmail_auth( "mailserver", "your_username", "your_password", "my@somewhere.com", [ "someone@somewhere.com" ], s)