Mail - e-mailを送るための簡単なsmtplibのラッパ

このモジュールはとてもシンプルなモジュールで(ソースコードはわずか20行)あり、CherryPyプログラムからemailを送ることができます。

このモジュールはMailと呼ばれるCherryClassの抽象クラスであり、smtpServerと呼ばれるメンバ変数とsendMailと呼ばれるメソッドを伴い鱒。

これを付くには、Mail CherryClassを派生し、__init__メソッド内にsmtpserverをセットし、それからemailを送るためにsendMailを呼び出します。

variable: smtpServer
Smtpサーバーのアドレスが入っている文字列です。

function: sendMail(sender, receiver, bcc, contentType, subject, msg)
この関数はパラメータに沿ってe-mailを送ります。全てのパラメータは文字列である必要があります。contentTypeは「text/plain」か「text/html」のどちらかです。contentTypeに依って、msgはプレーンテキストかhtmlテキストのどちらかを含みます。この関数はe-mailを送るためにPythonのsmtplibを使います。これはsmtpServer値を使ってemailを送ります。

例:

use Mail
CherryClass MyMail(Mail):
function:
    def __init__(self):
        self.smtpServer='smtp.site.com'
CherryClass Root:
mask:
    def index(self):
        <py-exec="myMail.sendMail('me@site.com', 'you@yourhost.com', '', 'text/plain', 'Hello', 'Hel
lo,\nthis is me')">
        <html><body>
            Hi, I just sent an e-mail to you@yourhost.com
        </body></html>


Debian User 2003-10-13