How does inbound mail work?

49 views
Skip to first unread message

Zeynel

unread,
Nov 19, 2010, 1:20:23 PM11/19/10
to Google App Engine
I'm reading the Receiving Email tutorial but so far I was unable to
make it work. I dont understand how to access the received email. Can
somebody explain?

I created the app.yaml and I added inbound services and url mapping:

application: hello-1-world
version: 1
runtime: python
api_version: 1

handlers:
- url: /favicon.ico
static_files: static/images/favicon.ico
upload: static/images/favicon.ico

- url: /_ah/mail/.+
script: handle_incoming_email.py
login: admin

- url: /.*
script: hw.py

inbound_services:
- mail

and I created a handle_incoming_email.py script in the same directory
as my app hello-1-world.

As far as I understand it, next I will send an email from the
development console http://localhost:8081/_ah/admin/inboundmail

to he...@hello-1-world.appspotmail.com

And my script handle_incoming_email.py should handle the incoming
mail.

So I sent the email to he...@hello-1-world.appspotmail.com

then in the development server I load

http://localhost:8081/_ah/mail/he...@hello-1-world.appspotmail.com

but there is nothing there. What am I missing?

Can you explain how this is supposed to work? Many thanks!

Geoffrey Spear

unread,
Nov 19, 2010, 2:20:52 PM11/19/10
to Google App Engine
/_ah/mail/<address> will get the mail posted to it by the email
service when it's sent to your application. Mail sent to your
appspotmail.com address will never be available to your development
server, and you shouldn't be visiting the _ah/email address yourself.
To simulate email in the dev server, you need to use the dashboard at
http://localhost:8081/_ah/admin/

On Nov 19, 1:20 pm, Zeynel <azeyn...@gmail.com> wrote:
> I'm reading the  Receiving Email tutorial but so far I was unable to
> make it work. I dont understand how to access the received email. Can
> somebody explain?
>
> I created the app.yaml and I added inbound services and url mapping:
>
> application: hello-1-world
> version: 1
> runtime: python
> api_version: 1
>
> handlers:
> - url: /favicon.ico
>   static_files: static/images/favicon.ico
>   upload: static/images/favicon.ico
>
> - url: /_ah/mail/.+
>   script: handle_incoming_email.py
>   login: admin
>
> - url: /.*
>   script: hw.py
>
> inbound_services:
> - mail
>
> and I created a handle_incoming_email.py script in the same directory
> as my app hello-1-world.
>
> As far as I understand it, next I will send an email from the
> development consolehttp://localhost:8081/_ah/admin/inboundmail
>
> to h...@hello-1-world.appspotmail.com
>
> And my script handle_incoming_email.py should handle the incoming
> mail.
>
> So I sent the email to h...@hello-1-world.appspotmail.com
>
> then in the development server I load
>
> http://localhost:8081/_ah/mail/h...@hello-1-world.appspotmail.com

Zeynel

unread,
Nov 19, 2010, 2:32:06 PM11/19/10
to Google App Engine
On Nov 19, 2:20 pm, Geoffrey Spear <geoffsp...@gmail.com> wrote:
> To simulate email in the dev server, you need to use the dashboard athttp://localhost:8081/_ah/admin/

Thanks. I send an email from http://localhost:8081/_ah/admin/inboundmail
but I am confused about how to access the content of the email "text"
in the following script. I created a handle_incoming_email.py script
and put the following handler in it:

class ReceiveEmail(InboundMailHandler):
def receive(self,message):
logging.info("Received email from %s" % message.sender)
plaintext = message.bodies(content_type='text/plain')
for text in plaintext:
txtmsg = ""
txtmsg = text[1].decode()
logging.info("Body is %s" % txtmsg)
self.response.out.write(txtmsg)


application = webapp.WSGIApplication([
ReceiveEmail.mapping()
], debug=True)

I assume that "plaintext" contains the body of the email and it is
decoded into "txtmsg". Correct? How do I access this "txtmsg"?

Thanks again.
Reply all
Reply to author
Forward
0 new messages