News for hackers. Stuff that matters.
Re:Envelopes - Python email for humans by ghc on Wednesday August 07, 2013 @02:12PM (#6174518)
If this works as well as Python's requests library, then you are my hero. I hate dealing with email in Python, because the standard library interfaces to email are horrible.

I have a have a project that could use this now, so I will give it a shot. I will report back with my findings.

Re:Envelopes - Python email for humans by fsckin on Wednesday August 07, 2013 @03:59PM (#6175214)
Anyone who calls their project "Library_Name for Humans" has big shoes to fill. Looking at the examples, it appears to be exactly that.
Re:Envelopes - Python email for humans by Chris2048 on Thursday August 08, 2013 @07:33AM (#6178261)
perhaps there should be an official group for 'for humans' projects?
Re:Envelopes - Python email for humans by tomekwojcik on Thursday August 08, 2013 @03:15AM (#6177691)
I'm aiming at Requests' robustness, but it's still a long way to go for Envelopes. Good news is - it works and sends e-mails :).

If you find any issues please report them at GitHub. Thanks and have fun.

Re:Envelopes - Python email for humans by ianstormtaylor on Wednesday August 07, 2013 @04:12PM (#6175292)
From an API standpoint:

(1) I feel like sending emails isn't a task that's going to be repeated endlessly across a codebase, so is it really necessary to save three characters by truncating "from_address" to "from_addr"? You lose clarity for very little gain.

(2) If truncating the above was so important, why is it "text_body" instead of just plain "body"? In this case, you'd lose almost no clarity.

I prefer APIs to not have unnecessarily abbreviated words—especially when, realistically, I'm going to type them once per file.

(Sorry, pet peeve.)

Re:Envelopes - Python email for humans by tomekwojcik on Thursday August 08, 2013 @03:20AM (#6177694)
The API is still young and I'm perfectly aware it could use some love (especially that I wrote the first Envelopes class at 3AM while trying to simplify my workflow).

I've been considering renaming "from_addr" and "to_addr" to "from" and "to" but this would cause conflicts with Python's keywords. I'm, however, all over renaming them to "from_address" and "to_address". As far as "cc_addrs" and "bcc_addrs" - I think I'll use full "address" there, too (for the sake of consistency).

As for "text_body" and "html_body" - I'd like to leave those as they are. Depending on the case I may use one of them, both of them or neither of them.

Thanks for your feedback, it's much appreciated :).

Re:Envelopes - Python email for humans by ihuman on Wednesday August 07, 2013 @04:15PM (#6175316)
It is called text_body because there is also an html_body.

http://tomekwojcik.github.io/envelopes/api/envelope.html

Re:Envelopes - Python email for humans by mey on Wednesday August 07, 2013 @04:56PM (#6175566)
So if you set both, will it auto-magically do multipart/mime/alt? That is pretty nice.
Re:Envelopes - Python email for humans by ianstormtaylor on Thursday August 08, 2013 @12:56AM (#6177396)
Ah good call. Maybe it's just my very maleable Javascript side talking, but if I were making this API in Javascript I'd probably have a "body" and do a super simple check if the first character is a "<", which will solve the 99.999% case for HTML vs. text emails.
Re:Envelopes - Python email for humans by ihuman on Thursday August 08, 2013 @12:58AM (#6177402)
But then your emails can't have HTML and a plaintext backup.
Re:Envelopes - Python email for humans by ianstormtaylor on Thursday August 08, 2013 @01:03AM (#6177412)
Ah I should have clarified that "body" would be a shorthand of sorts. I'd still have an "html" and "text" alternative to satisfy the case where you want to set both, and in that case "text" and "html" are very meaningful. But the "body" makes the simple case, and the examples extremely clean too.
Re:Envelopes - Python email for humans by benhoyt on Wednesday August 07, 2013 @06:16PM (#6176057)
Agreed about abbreviations.

To distinguish "text_body" and "html_body", what about simply "text" and "html"? That's what we use internally.

Also, how does one send To: multiple addresses with this library? I think it'd be good if to_address could be a list (or their was a separate to_addresses, which could be a list).

I like it how cc_addrs / bcc_addrs can be a list already, of either addresses or (email, name) tuples. Why not do the same thing from from_address and to_addresses, and get rid of from_name and to_name?

Re:Envelopes - Python email for humans by ianstormtaylor on Thursday August 08, 2013 @12:57AM (#6177400)
Honestly I didn't even see the "cc_addrs" and "bcc_addrs". Those are horrible. Now you have complex abbreviations that are pluralized! I completely agree.

And while we're making them accept lists or tuples, change their names to: "to", "from", "cc" and "bcc". Very clear and still a tiny amount of characters.

Re:Envelopes - Python email for humans by fsniper on Thursday August 08, 2013 @04:24AM (#6177829)
that's what I was thinking of. Accepting dicts or tuples would be ok. Even just using [ "Name <email address>", "name <email address>"] would be more human.
Re:Envelopes - Python email for humans by tomekwojcik on Thursday August 08, 2013 @04:42AM (#6177870)
Note that, for CC and BCC addresses, there's a number of accepted formats. Consult docs for more info: http://tomekwojcik.github.io/envelopes/api/envelope.html
Re:Envelopes - Python email for humans by fsniper on Thursday August 08, 2013 @08:27AM (#6178443)
I'm talking about to field also.
Re:Envelopes - Python email for humans by habitue on Thursday August 08, 2013 @12:22AM (#6177331)
I feel I should mention Mailer

https://pypi.python.org/pypi/mailer

I think everyone who has ever used the python standard library email modules has had the thought "Well, if I just made a small wrapper around this... it wouldn't be so bad"

And just about everyone who thought that did it.

Re:Envelopes - Python email for humans by codegeek on Wednesday August 07, 2013 @02:25PM (#6174610)
Looks pretty good. Being a Flask user, happy to see the flask example as well. Would definitely try and use it in side projects of mine. You open to any forks and/or pull requests ?
Re:Envelopes - Python email for humans by dignan on Wednesday August 07, 2013 @03:44PM (#6175124)
As a Flask user, you might want to check out Flask-Mail http://pythonhosted.org/flask-mail/
Re:Envelopes - Python email for humans by codegeek on Wednesday August 07, 2013 @04:03PM (#6175239)
Thx. I know of flask-mail already. Just wanted to see how different would the "envelopes" be .
Re:Envelopes - Python email for humans by tghw on Wednesday August 07, 2013 @04:10PM (#6175278)
If they can add IMAP, POP, possibly Exchange, and good email parsing (it's truly a pain in the ass to do yourself) this will be a killer library.
Re:Envelopes - Python email for humans by anonymoushn on Wednesday August 07, 2013 @09:15PM (#6176803)
I'd also be interested in an email parsing library for Python. Last time I used Twisted to read email the parser was completely worthless and could not be fixed other than by rewriting it from scratch.
Re:Envelopes - Python email for humans by topherjaynes on Wednesday August 07, 2013 @07:02PM (#6176255)
Nice wrapper, though it took me a while to get it to work. Tried with Google SMTP, but ended up throwing Sendgrid on a heroku app and hit that api.

Wondering if a debug mode would be helpful for the initial set up. See what requests are being sent/received to see what the possible errors are.

Re:Envelopes - Python email for humans by tomekwojcik on Thursday August 08, 2013 @03:24AM (#6177709)
Debug mode is a nice catch. Thanks.

As far as GMail SMTP goes, I've been using Envelopes over GMail SMTP for about a week with great success. The first example in the docs shows just that. Also, I have customized SMTP subclasses for GMail, SendGrid and local Mailcatcher in the pipeline. Using one of them, you'll only have to provide your creds to send e-mails.

Re:Envelopes - Python email for humans by omaranto on Wednesday August 07, 2013 @06:19PM (#6176080)
What is the advantage of having an Envelope class? Why not just have a send function?
Re:Envelopes - Python email for humans by YokoZar on Wednesday August 07, 2013 @07:01PM (#6176250)
Maybe so you can more deliberately build different parts of the email in different parts of the code without having to create your own set of variables for that.
Re:Envelopes - Python email for humans by TemporalAnomaly on Thursday August 08, 2013 @05:31AM (#6177979)
I find it a little weird that you would create the email in one part of the code and then send it somewhere else though. The only advantage I can think off is something like falling back to another connection if the primary one fails. But it's strange to support reuse of messages while at the same time not being able to reuse a connection.

Why not have a set of classes for flexibility and simple helper functions for the most common cases? Requests is so great to use because the API matches the expectations of its users (how do I make a GET request? oh, use the get function...) and I think for email a single send function does what people want most of the time.

send( 'smtp.googlemail.com', login='[email protected]', password='password', from_address=u'[email protected]', from_name=u'From Example', to_address=u'[email protected]', to_name=u'To Example', subject=u'Envelopes demo', text=u"I'm a helicopter!" )

connection = Connection( 'smtp.googlemail.com', login='[email protected]', password='password' )

message = Envelope( from_address=u'[email protected]', from_name=u'From Example', to_address=u'[email protected]', to_name=u'To Example', subject=u'Envelopes demo', text=u"I'm a helicopter!" )

message.add_attachment('/Users/bilbo/Pictures/helicopter.jpg')

connection.send(message)

Re:Envelopes - Python email for humans by tomekwojcik on Thursday August 08, 2013 @07:10AM (#6178209)
envelopes.conn.SMTP is a wrapper for smtplib.SMTP that supports Envelope objects and is reusable. Envelope.send() is just a shorthand you can use if you don't care about reusing connections.

For requests it's simpler to support top-level functions, since in general HTTP request is self-contained. Envelope (or email.mime.MIMEMessage) object isn't enough to send an e-mail - you need to know the SMTP host, port, creds and set up the connection. While it's certainly possible to write envelopes.send() function that'd internally create an Envelope object and send it (all based on the args the function gets) I don't think it's that crucial.

Re:Envelopes - Python email for humans by ajaxaddicted on Wednesday August 07, 2013 @05:13PM (#6175676)
Envelopes looks very good for sending emails and for reading emails there is another cool library - Imbox https://github.com/martinrusev/imbox
Re:Envelopes - Python email for humans by bobbyi_settv on Wednesday August 07, 2013 @02:32PM (#6174664)
We use boto to send email via Amazon's Simple Email Service and it is fairly simple. SES allows you to send up to 2000 emails per day for free.
Re:Envelopes - Python email for humans by jp_sc on Wednesday August 07, 2013 @04:26PM (#6175380)
Would you be willing to collaborate a SES mailer wrapper for this similar project? https://github.com/lucuma/MailShake
Re:Envelopes - Python email for humans by gpsarakis on Wednesday August 07, 2013 @04:57PM (#6175574)
Seems really nice with a first glance. Are you considering any Django support in the future?
Re:Envelopes - Python email for humans by mattoc on Wednesday August 07, 2013 @09:20PM (#6176822)
Django's Email API is already pretty solid, see the EmailMessage[0] class. Attachments and multiple MIME types are handled for sending text & html versions of the email body.

However, given that Django is just Python there's nothing precluding you from using the library as a drop-in replacement.

[0] https://docs.djangoproject.com/en/dev/topics/email/#emailmes...

Re:Envelopes - Python email for humans by tomekwojcik on Thursday August 08, 2013 @03:26AM (#6177715)
I don't generally do Django, but I don't think it should be a problem. Just a word of warning - if you're going to use a global per-app SMTP connection remember to wrap it in connstack. The Flask example shows this and it shouldn't be hard to do the same in Django.