Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: Complete example. #3

Closed
laveur opened this issue May 4, 2012 · 13 comments
Closed

Request: Complete example. #3

laveur opened this issue May 4, 2012 · 13 comments

Comments

@laveur
Copy link

laveur commented May 4, 2012

I would love to start using this. But the problem is I don't know exactly what to once I get a call to my handle method. Could this possibly used to make a very simple email server? Could I find a way to replace say Courier? An example that shows you what to do once you have it set up and running would be awesome.

@j-hernandez
Copy link

plus onezo - Need a small SMTP server on an intranet and this seems like it'd be suitable (read: less madness inducing) than setting up one of the usual suspects.

@obrienmd
Copy link

obrienmd commented May 4, 2012

I'd love full documentation of what to, sender and body look like. Is body a set of keys and values, an object, etc.? Where do I grab all the fun header items?

@birep
Copy link

birep commented May 8, 2012

If we're talking about examples we'd love to see, would this be appropriate for receiving an email with an image attachment, saving the file, and putting an entry in a database?

@j-hernandez
Copy link

And wildcard subdomains so I can integrate comments via email into my issue tracker.

@j-hernandez
Copy link

What I'm saying is: do my work for me please and thank you.

Just joshin' but yeah a boilerplate example to jump off of would be pretty rad.

@adambard
Copy link

adambard commented May 9, 2012

I have an example where I just forward the message to another SMTP server (I was proxying Jenkins, which has no STARTTLS support, to a mail server that only supports STARTTLS). Is that the sort of boilerplate you'd want?

The handler just gets the to (list) and from (string) addresses and the body text, you have a lot of freedom to do whatever you want with that.

@j-hernandez
Copy link

As good a starting point as any. Gist? Also: noice.

@obrienmd
Copy link

obrienmd commented May 9, 2012

By body are you including headers, different body formats and attachments?

Great job on the project!
On May 8, 2012 7:20 PM, "Adam Bard" <
reply@reply.github.com>
wrote:

I have an example where I just forward the message to another SMTP server
(I was proxying Jenkins, which has no STARTTLS support, to a mail server
that only supports STARTTLS). Is that the sort of boilerplate you'd want?

The handler just gets the to (list) and from (string) addresses and the
body text, you have a lot of freedom to do whatever you want with that.


Reply to this email directly or view it on GitHub:
#3 (comment)

@adambard
Copy link

adambard commented May 9, 2012

"""
Proxy smtp to a starttls server with authentication, from a local
connection.
"""
from inbox import Inbox
from smtplib import SMTP

inbox = Inbox()

SMTP_HOST = 'mail.example.com'
SMTP_USERNAME = 'username'
SMTP_PASSWORD = 'password'

@inbox.collate
def handle(to, sender, body):
    """
    Forward a message via an authenticated SMTP connection with
    starttls.
    """
    conn = SMTP(SMTP_HOST, 25, 'localhost')

    conn.starttls()
    conn.ehlo_or_helo_if_needed()
    conn.login(SMTP_USERNAME, SMTP_PASSWORD)
    conn.sendmail(sender, to, body)
    conn.quit()

inbox.serve(address='0.0.0.0', port=4467)

@adambard
Copy link

adambard commented May 9, 2012

And an example message body

Date: Wed, 9 May 2012 09:57:50 -0700 (PDT)
From: abard@example.com
To: abard@example.com, someoneelse@example.com
Message-ID: <JavaMail.jenkins@example.net>
In-Reply-To: <JavaMail.jenkins@example.net>
References: <JavaMail.jenkins@example.net>
Subject: Jenkins build is back to stable
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit

Message text goes here.

@j-hernandez
Copy link

Cheers! A great starting point, thanks for sharing

@zebozhuang
Copy link

How does it call the handle?We know we must call the process_message function, but we can not get it out and call it!

@avinassh
Copy link

Any example about receiving emails?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants