File: Mail.tex

package info (click to toggle)
cherrypy 0.10-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 10,324 kB
  • ctags: 1,759
  • sloc: python: 14,411; sh: 6,915; perl: 2,472; makefile: 76
file content (43 lines) | stat: -rwxr-xr-x 1,890 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
\section{\module{Mail} --- Simple smtplib wrapper to send e-mails.}
\declaremodule{standard}{Mail}

This module is a very simple module (the source code is only 20 lines) that allows you to send e-mails from
your CherryPy program.

The module defines an abstract CherryClass called \class{Mail}, with one member variable called \var{smtpServer} and
one method called \var{sendMail}.

To use it, just derive the \var{Mail} CherryClass, set \var{smtpServer} in the \var{__init__} method, and then
call \var{sendMail} to send an e-mail:

\begin{memberdesc}{variable: smtpServer}
String containing the address of the Smtp server
\end{memberdesc}

\begin{funcdesc}{function: sendMail}{sender, receiver, bcc, contentType, subject, msg}
This functions sends an e-mail according to the parameters. All parameters must be a string. \var{contentType} should be
either "text/plain" or "text/html". Depending on \var{contentType}, \var{msg} should contain either plain text or html text.
This functions uses Python's \var{smtplib} library to send the e-mail. It uses the value of \var{smtpServer} to send
the email.
\end{funcdesc}

\begin{funcdesc}{function: sendHtmlMail}{sender, receiver, bcc, subject, txtmsg, htmlmsg}
This functions sends an HTML e-mail according to the parameters. All parameters must be a string.
This functions uses Python's \var{smtplib} and \var{MimeWriter} modules to send the e-mail. It uses the value of \var{smtpServer} to send the email.
\end{funcdesc}

Exemple:
\begin{verbatim}
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', 'Hello,\nthis is me')">
        <html><body>
            Hi, I just sent an e-mail to you@yourhost.com
        </body></html>
\end{verbatim}