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.

  • 2
    @guetti That sounds like "for human beings" is your opinion about the ease of use of the standard email module. But we cannot give you advice based on opinions as input. So please edit your question and describe the requirements for the alternative module in measurable terms.
    – user416
    Oct 30 '14 at 15:51
  • Seconding Jan, and giving you further hints: Please take a look at What is required for a question to contain "enough information"? for what else might either be missing, or otherwise improve your chances for good answers. Thanks!
    – Izzy
    Oct 30 '14 at 15:53
  • 1
    @JanDoggen: I'm not sure how you interpreted "for human beings" as OP's description of the standard email module. He's using the catchphrase from requests, 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 as requests, but for e-mail instead of HTTP.
    – John Y
    Oct 30 '14 at 22:16
  • I wrote "Handling unicode mails with the email module from the standard library is no fun.". I am not a native speaker. For me this is a requirement. Have you ever handled unicode with the python email module? If not, please comment on different questions.
    – guettli
    Oct 31 '14 at 10:16
  • @john I should've said the NOT easy of use
    – user416
    Oct 31 '14 at 11:05

I think you might be looking for pyzmail - from the examples:

import pyzmail

sender=(u'Me', 'me@foo.com')
recipients=[(u'Him', 'him@bar.com'), 'just@me.com']
subject=u'the subject'
text_content=u'Bonjour aux Fran\xe7ais'

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', \

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())
        print 'success'
    print 'error:', ret

Not quite SMTP for humans but maybe getting there!

  • 2
    Thank you for this answer. I searched the web before asking here. Maybe I was blind. Again, thank you.
    – guettli
    Nov 2 '14 at 20:38

Be sure to check envelopes as well!

from envelopes import Envelope, GMailSMTP

envelope = Envelope(
    from_addr=(u'from@example.com', u'From Example'),
    to_addr=(u'to@example.com', u'To Example'),
    subject=u'Envelopes demo',
    text_body=u"I'm a helicopter!"

# Send the envelope using an ad-hoc connection...
envelope.send('smtp.googlemail.com', login='from@example.com',
              password='password', tls=True)

# Or send the envelope using a shared GMail connection...
gmail = GMailSMTP('from@example.com', 'password')

Note: The documentation says that it should be considered as beta. Use with caution.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.