Better HN
topnewbestaskshowjobs
Log inSign up

TemporalAnomaly

1 karma · joined Aug 8, 2013 (13y ago) · 1 submissions

Submissions

comment 13y ago · link · parent

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='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)