<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>techno.blog(&#34;Dion&#34;) &#187; Python</title>
	<atom:link href="http://almaer.com/blog/tag/python/feed" rel="self" type="application/rss+xml" />
	<link>http://almaer.com/blog</link>
	<description>blogging about life, the universe, and everything tech</description>
	<lastBuildDate>Tue, 28 Aug 2012 14:41:55 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>smtp2web.com: Bridge SMTP to HTTP; Let App Engine accept Email</title>
		<link>http://almaer.com/blog/smtp2webcom-bridge-smtp-to-http-let-app-engine-accept-email</link>
		<comments>http://almaer.com/blog/smtp2webcom-bridge-smtp-to-http-let-app-engine-accept-email#comments</comments>
		<pubDate>Tue, 10 Jun 2008 16:41:50 +0000</pubDate>
		<dc:creator>dion</dc:creator>
				<category><![CDATA[Google]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[appengine]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://almaer.com/blog/smtp2webcom-bridge-smtp-to-http-let-app-engine-accept-email</guid>
		<description><![CDATA[Nick Johnson, of Google, has created a nice bridge service smtp2web.com: Allow App Engine apps to receive email.
This is perfect timing, as after my App Engine talk in Prague, a nice gent came up to me and asked for just this. He wanted to process email in his application and didn&#8217;t think he could.

One shortcoming [...]]]></description>
			<content:encoded><![CDATA[<p>Nick Johnson, of Google, has created a nice bridge service <a href="http://groups.google.com/group/google-appengine/browse_thread/thread/7f48e15a7cedafa6">smtp2web.com: Allow App Engine apps to receive email</a>.</p>
<p>This is perfect timing, as after my App Engine talk in Prague, a nice gent came up to me and asked for just this. He wanted to process email in his application and didn&#8217;t think he could.</p>
<blockquote><p>
One shortcoming of purely HTTP-based webapps such as App Engine is<br />
that they can&#8217;t receive email. I know that some people are wanting to<br />
create App Engine apps that do this, so I put together a service to<br />
facilitate this. It runs as a standard SMTP server, and sends all the<br />
email it receives via HTTP POST to a user-designated URL. It&#8217;s free to<br />
use (but <a href="http://www.smtp2web.com/about">not to abuse</a>)
</p></blockquote>
<p>To use the service, you setup an email account (say dalmaer@smtp2web.com) and a URL to point too. Of course, if you want an email on your own domain you could alias dalmaer@yourdomain.com to dalmaer@smtp2web.com).</p>
<p>Then, you would configure an App Engine controller to receive the email contents:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> google.<span style="color: black;">appengine</span>.<span style="color: black;">ext</span> <span style="color: #ff7700;font-weight:bold;">import</span> webapp
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">email</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> EmailHandler<span style="color: black;">&#40;</span>webapp.<span style="color: black;">RequestHandler</span><span style="color: black;">&#41;</span>:
  <span style="color: #ff7700;font-weight:bold;">def</span> post<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
    sender = <span style="color: #008000;">self</span>.<span style="color: black;">request</span>.<span style="color: black;">GET</span>.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;from&quot;</span>, <span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#41;</span>
    recipient = <span style="color: #008000;">self</span>.<span style="color: black;">request</span>.<span style="color: black;">GET</span>.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;to&quot;</span>, <span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#41;</span>
    message = <span style="color: #dc143c;">email</span>.<span style="color: black;">message_from_string</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">request</span>.<span style="color: black;">body</span><span style="color: black;">&#41;</span>
    <span style="color: #808080; font-style: italic;"># Do stuff with the email message</span></pre></div></div>

<p>The code for the service has also been <a href="http://code.google.com/p/smtp2web/">released as open source on Google Code</a> so you can check it out. You will find that it runs as a Twisted application:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> twisted.<span style="color: black;">application</span> <span style="color: #ff7700;font-weight:bold;">import</span> service
<span style="color: #ff7700;font-weight:bold;">from</span> twisted.<span style="color: black;">application</span> <span style="color: #ff7700;font-weight:bold;">import</span> internet
<span style="color: #ff7700;font-weight:bold;">from</span> twisted.<span style="color: black;">enterprise</span> <span style="color: #ff7700;font-weight:bold;">import</span> adbapi
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>
<span style="color: #dc143c;">sys</span>.<span style="color: black;">path</span>.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">dirname</span><span style="color: black;">&#40;</span>__file__<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> smtp2web
&nbsp;
application = service.<span style="color: black;">Application</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;smtp2web Service&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
settings = smtp2web.<span style="color: black;">Settings</span><span style="color: black;">&#40;</span>secret_key=<span style="color: #483d8b;">&quot;&lt;enter secret key here&gt;&quot;</span>,
                             state_file=<span style="color: #483d8b;">&quot;state&quot;</span>, master_host=<span style="color: #483d8b;">&quot;localhost:8081&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
smtpServerFactory = smtp2web.<span style="color: black;">ESMTPFactory</span><span style="color: black;">&#40;</span>settings<span style="color: black;">&#41;</span>
smtpServerService = internet.<span style="color: black;">TCPServer</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">2025</span>, smtpServerFactory<span style="color: black;">&#41;</span>
smtpServerService.<span style="color: black;">setServiceParent</span><span style="color: black;">&#40;</span>application<span style="color: black;">&#41;</span></pre></div></div>

<p>Thanks for doing this Nick!</p>
<p><em>NOTE: <a href="http://mailhook.org/">Mailhook</a> is another service (pay) that does something similar</a></em></p>
]]></content:encoded>
			<wfw:commentRss>http://almaer.com/blog/smtp2webcom-bridge-smtp-to-http-let-app-engine-accept-email/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
