seitime-frappe/docs/html/email_lib.html
2011-06-08 14:24:18 +05:30

223 lines
No EOL
13 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>email_lib — Email &mdash; Documentation</title>
<link rel="stylesheet" href="_static/sphinxdoc.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '',
VERSION: '',
COLLAPSE_MODINDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="top" title="Documentation" href="index.html" />
<link rel="up" title="3. Server Side API" href="server_side_api.html" />
<link rel="next" title="profile — Profile" href="profile.html" />
<link rel="prev" title="utils — Utilities Module" href="utils_server.html" />
</head>
<body>
<div style="background-color: #FFF; text-align: left; padding: 8px 0px"><img src="_static/banner300910.gif"></div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="modindex.html" title="Global Module Index"
accesskey="M">modules</a> |</li>
<li class="right" >
<a href="profile.html" title="profile — Profile"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="utils_server.html" title="utils — Utilities Module"
accesskey="P">previous</a> |</li>
<li><a href="index.html">Documentation</a> &raquo;</li>
<li><a href="server_side_api.html" accesskey="U">3. Server Side API</a> &raquo;</li>
</ul>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<h3><a href="index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference external" href=""><tt class="docutils literal"><span class="pre">email_lib</span></tt> &#8212; Email</a><ul>
<li><a class="reference external" href="#email-object">Email object</a></li>
<li><a class="reference external" href="#example">Example</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="utils_server.html"
title="previous chapter"><tt class="docutils literal docutils literal"><span class="pre">utils</span></tt> &#8212; Utilities Module</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="profile.html"
title="next chapter"><tt class="docutils literal"><span class="pre">profile</span></tt> &#8212; Profile</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/email_lib.txt"
rel="nofollow">Show Source</a></li>
</ul>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<input type="text" name="q" size="18" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="module-email_lib">
<h1><tt class="xref docutils literal"><span class="pre">email_lib</span></tt> &#8212; Email<a class="headerlink" href="#module-email_lib" title="Permalink to this headline"></a></h1>
<div class="section" id="email-object">
<h2>Email object<a class="headerlink" href="#email-object" title="Permalink to this headline"></a></h2>
<dl class="class">
<dt id="email_lib.Email">
<em class="property">class </em><tt class="descclassname">email_lib.</tt><tt class="descname">Email</tt><big>(</big><em>self</em>, <em>sender=''</em>, <em>recipients=</em><span class="optional">[</span><span class="optional">]</span>, <em>subject=''</em><big>)</big><a class="headerlink" href="#email_lib.Email" title="Permalink to this definition"></a></dt>
<dd><p>Wrapper on the email module. Email object represents emails to be sent to the client.
Also provides a clean way to add binary <cite>FileData</cite> attachments</p>
<dl class="attribute">
<dt id="email_lib.Email.sender">
<tt class="descname">sender</tt><a class="headerlink" href="#email_lib.Email.sender" title="Permalink to this definition"></a></dt>
<dd>sender&#8217;s email</dd></dl>
<dl class="attribute">
<dt id="email_lib.Email.reply_to">
<tt class="descname">reply_to</tt><a class="headerlink" href="#email_lib.Email.reply_to" title="Permalink to this definition"></a></dt>
<dd>[Optional] if reply_to is not same as sender</dd></dl>
<dl class="attribute">
<dt id="email_lib.Email.recipients">
<tt class="descname">recipients</tt><a class="headerlink" href="#email_lib.Email.recipients" title="Permalink to this definition"></a></dt>
<dd><cite>list</cite> of recipients or a string separated by comma (,) or semi-colon (;)</dd></dl>
<dl class="attribute">
<dt id="email_lib.Email.subject">
<tt class="descname">subject</tt><a class="headerlink" href="#email_lib.Email.subject" title="Permalink to this definition"></a></dt>
<dd>email subject</dd></dl>
<dl class="attribute">
<dt id="email_lib.Email.msg">
<tt class="descname">msg</tt><a class="headerlink" href="#email_lib.Email.msg" title="Permalink to this definition"></a></dt>
<dd>message object <cite>email.mime.multipart.MIMEMultipart</cite></dd></dl>
<dl class="attribute">
<dt id="email_lib.Email.cc">
<tt class="descname">cc</tt><a class="headerlink" href="#email_lib.Email.cc" title="Permalink to this definition"></a></dt>
<dd><cite>list</cite> of cc email ids</dd></dl>
<dl class="method">
<dt id="email_lib.Email.set_message">
<tt class="descname">set_message</tt><big>(</big><em>message</em>, <em>mime_type='text/html'</em><big>)</big><a class="headerlink" href="#email_lib.Email.set_message" title="Permalink to this definition"></a></dt>
<dd>append the message with MIME content</dd></dl>
<dl class="method">
<dt id="email_lib.Email.attach">
<tt class="descname">attach</tt><big>(</big><em>file_id</em><big>)</big><a class="headerlink" href="#email_lib.Email.attach" title="Permalink to this definition"></a></dt>
<dd>attach a file from the <cite>FileData</cite> table</dd></dl>
<dl class="method">
<dt id="email_lib.Email.validate">
<tt class="descname">validate</tt><big>(</big><big>)</big><a class="headerlink" href="#email_lib.Email.validate" title="Permalink to this definition"></a></dt>
<dd>validate the email ids</dd></dl>
<dl class="method">
<dt id="email_lib.Email.setup">
<tt class="descname">setup</tt><big>(</big><big>)</big><a class="headerlink" href="#email_lib.Email.setup" title="Permalink to this definition"></a></dt>
<dd>setup the SMTP (outgoing) server from <cite>Control Panel</cite> or defs.py</dd></dl>
<dl class="method">
<dt id="email_lib.Email.send">
<tt class="descname">send</tt><big>(</big><big>)</big><a class="headerlink" href="#email_lib.Email.send" title="Permalink to this definition"></a></dt>
<dd>send the message</dd></dl>
</dd></dl>
<dl class="method">
<dt id="email_lib.validate_email_add">
<tt class="descclassname">email_lib.</tt><tt class="descname">validate_email_add</tt><big>(</big><em>email_id</em><big>)</big><a class="headerlink" href="#email_lib.validate_email_add" title="Permalink to this definition"></a></dt>
<dd>Validate the email id</dd></dl>
<dl class="method">
<dt id="email_lib.sendmail">
<tt class="descclassname">email_lib.</tt><tt class="descname">sendmail</tt><big>(</big><em>recipients</em>, <em>sender=''</em>, <em>msg=''</em>, <em>subject='</em><span class="optional">[</span>, <em>No Subject</em><span class="optional">]</span>, <em>'</em>, <em>parts=</em><span class="optional">[</span><span class="optional">]</span>, <em>cc=</em><span class="optional">[</span><span class="optional">]</span>, <em>attach=</em><span class="optional">[</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#email_lib.sendmail" title="Permalink to this definition"></a></dt>
<dd>Short cut to method to send an email</dd></dl>
</div>
<div class="section" id="example">
<h2>Example<a class="headerlink" href="#example" title="Permalink to this headline"></a></h2>
<p>Email with attachments:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c"># get attachments</span>
<span class="n">al</span> <span class="o">=</span> <span class="n">sql</span><span class="p">(</span><span class="s">&#39;select file_list from `tab</span><span class="si">%s</span><span class="s">` where name=&quot;</span><span class="si">%s</span><span class="s">&quot;&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">dt</span><span class="p">,</span> <span class="n">dn</span><span class="p">))</span>
<span class="k">if</span> <span class="n">al</span><span class="p">:</span>
<span class="n">al</span> <span class="o">=</span> <span class="n">al</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;</span><span class="se">\n</span><span class="s">&#39;</span><span class="p">)</span>
<span class="c"># create the object</span>
<span class="n">email</span> <span class="o">=</span> <span class="n">server</span><span class="o">.</span><span class="n">EMail</span><span class="p">(</span><span class="s">&#39;test@webnotestech.com&#39;</span><span class="p">,</span> <span class="p">[</span><span class="s">&#39;a@webnotestech.com&#39;</span><span class="p">,</span> <span class="s">&#39;b@webnotestech.com&#39;</span><span class="p">],</span> <span class="s">&#39;this is a test&#39;</span><span class="p">)</span>
<span class="c"># add some intro</span>
<span class="n">email</span><span class="o">.</span><span class="n">set_message</span><span class="p">(</span><span class="n">replace_newlines</span><span class="p">(</span><span class="s">&#39;Hi</span><span class="se">\n\n</span><span class="s">You are being sent </span><span class="si">%s</span><span class="s"> </span><span class="si">%s</span><span class="se">\n\n</span><span class="s">Thanks&#39;</span> <span class="o">%</span> <span class="n">dt</span><span class="p">,</span> <span class="n">dn</span><span class="p">))</span>
<span class="c"># add attachments</span>
<span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="n">al</span><span class="p">:</span>
<span class="n">email</span><span class="o">.</span><span class="n">attach</span><span class="p">(</span><span class="n">a</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;,&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">])</span>
<span class="c"># send</span>
<span class="n">email</span><span class="o">.</span><span class="n">send</span><span class="p">()</span>
</pre></div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="modindex.html" title="Global Module Index"
>modules</a> |</li>
<li class="right" >
<a href="profile.html" title="profile — Profile"
>next</a> |</li>
<li class="right" >
<a href="utils_server.html" title="utils — Utilities Module"
>previous</a> |</li>
<li><a href="index.html">Documentation</a> &raquo;</li>
<li><a href="server_side_api.html" >3. Server Side API</a> &raquo;</li>
</ul>
</div>
<div class="footer">
&copy; Copyright 2010, Rushabh Mehta.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.3.
</div>
</body>
</html>