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.
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)