Envelopes - Python email for humans
tomekwojcik.github.io
tomekwojcik.github.io
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.
If you find any issues please report them at GitHub. Thanks and have fun.
(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.)
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?
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.
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 :).
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.
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.
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.
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='from@example.com', password='password', from_address=u'from@example.com', from_name=u'From Example', to_address=u'to@example.com', to_name=u'To Example', subject=u'Envelopes demo', text=u"I'm a helicopter!" )
connection = Connection( 'smtp.googlemail.com', login='from@example.com', password='password' )
message = Envelope( from_address=u'from@example.com', from_name=u'From Example', to_address=u'to@example.com', 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)
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.
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...