Is there an alternative email
module in Python?
Like requests
is a "HTTP library, written in Python, for human beings"
Handling unicode mails with the email module from the standard library is no fun.
Software Recommendations Stack Exchange is a question and answer site for people seeking specific software recommendations. It only takes a minute to sign up.
Sign up to join this communityI think you might be looking for pyzmail - from the examples:
import pyzmail
sender=(u'Me', '[email protected]')
recipients=[(u'Him', '[email protected]'), '[email protected]']
subject=u'the subject'
text_content=u'Bonjour aux Fran\xe7ais'
prefered_encoding='iso-8859-1'
text_encoding='iso-8859-1'
payload, mail_from, rcpt_to, msg_id=pyzmail.compose_mail(\
sender, \
recipients, \
subject, \
prefered_encoding, \
(text_content, text_encoding), \
html=None, \
attachments=[('attached content', 'text', 'plain', 'text.txt', \
'us-ascii')])
smtp_host='smtp.gmail.com'
smtp_port=587
smtp_mode='tls'
smtp_login='[email protected]'
smtp_password='my.gmail.password'
ret=pyzmail.send_mail(payload, mail_from, rcpt_to, smtp_host, \
smtp_port=smtp_port, smtp_mode=smtp_mode, \
smtp_login=smtp_login, smtp_password=smtp_password)
if isinstance(ret, dict):
if ret:
print 'failed recipients:', ', '.join(ret.keys())
else:
print 'success'
else:
print 'error:', ret
Not quite SMTP for humans but maybe getting there!
Be sure to check envelopes as well!
from envelopes import Envelope, GMailSMTP
envelope = Envelope(
from_addr=(u'[email protected]', u'From Example'),
to_addr=(u'[email protected]', u'To Example'),
subject=u'Envelopes demo',
text_body=u"I'm a helicopter!"
)
envelope.add_attachment('/Users/bilbo/Pictures/helicopter.jpg')
# Send the envelope using an ad-hoc connection...
envelope.send('smtp.googlemail.com', login='[email protected]',
password='password', tls=True)
# Or send the envelope using a shared GMail connection...
gmail = GMailSMTP('[email protected]', 'password')
gmail.send(envelope)
Note: The documentation says that it should be considered as beta. Use with caution.
email
module. He's using the catchphrase fromrequests
, which is an improvement over standard Python modules. I'm totally new here, so I don't quite know what level of subjectiveness is acceptable, but it sounds to me as though OP is after something that is of a similar level of abstraction and ease of use asrequests
, but for e-mail instead of HTTP.