<commit_before>.. _quickstart:

Quickstart
==========

This page gives a good introduction to Mailthon, and assumes
that you already have Mailthon installed. Head over to the
:ref:`installation` section if you do not.

Creating an Email
-----------------

Creating a minimal email looks like the following::

    from mailthon.envelope import Envelope
    from mailthon.enclosure import PlainText

    envelope = Envelope( 
        headers={
            'Sender': 'sender <<EMAIL>>',
            'To': '<EMAIL>',
            'Subject': 'Hello World!',
        },
        enclosure=[
            PlainText('Hi!'),
        ]
    )<commit_msg>add comparison section [skip ci]<commit_after>.. _quickstart:

Quickstart
==========

This page gives a good introduction to Mailthon, and assumes
that you already have Mailthon installed. Head over to the
:ref:`installation` section if you do not.

Comparison
----------

A comparison between using the standard library
`smtplib <https://docs.python.org/2/library/smtplib.html>`_ module and
Mailthon::

    from smtplib import SMTP
    from email.mime.multipart import MIMEMultipart
    from email.mime.text import MIMEText
    from email.mime.image import MIMEImage

    text = MIMEText('<html><p>Hi!</p></html>', 'html')
    image = MIMEImage(open('cats.gif', 'rb').read())

    mime = MIMEMultipart()
    mime['Sender'] = 'Me <<EMAIL>>'
    mime['To'] = 'Them <<EMAIL>>'
    mime.attach(text)
    mime.attach(image)

    smtp = SMTP(host='smtp.server.com', port=587)
    smtp.ehlo()
    smtp.starttls()
    smtp.login('username', 'password')
    smtp.sendmail(
        mime['Sender'],
        mime['To'],
        mime.as_string()
    )
    smtp.quit()

Using Mailthon all this cruft is reduced::

    from mailthon import postman, email
    
    smtp = postman(host='smtp.server.com', port=587, auth=('username', 'password'))
    smtp.send(email(
        sender='Me <<EMAIL>>',
        receivers=['Them <<EMAIL>>'],
        content='<html><p>Hi!</p></html>',
        attachments=[
            'cats.gif',
        ]
    ))

Quoting K<NAME>, "things shouldn't be like that,
not in Python.".


Creating an Email
-----------------

Creating a minimal email looks like the following::

    from mailthon.envelope import Envelope
    from mailthon.enclosure import PlainText

    envelope = Envelope( 
        headers={
            'Sender': 'sender <<EMAIL>>',
            'To': '<EMAIL>',
            'Subject': 'Hello World!',
        },
        enclosure=[
            PlainText('Hi!'),
        ]
    )
{'fraction_non_alphanumeric': 0.15172955974842767, 'fraction_numerical': 0.002751572327044025, 'mean_word_length': 2.5495118549511857, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6231103', 'n_tokens_mistral': 794, 'n_tokens_neox': 761, 'n_words': 218}