#!/usr/bin/python3

'''

This program sends two emails to yourself.

The first email contains a short text.

The second email demonstrates how to send 
a multi-line message with two image attachments.

'''

import mailupdater, os

def main():

    # Make sure test image files exist.
    # In this demonstration, 32x32 pixel images of
    # a horse and car will be emailed to you.

    FILE_DIRECTORY = os.path.dirname(__file__)
    SAMPLE_FOLDER = os.path.join(FILE_DIRECTORY, "samples")
    HORSE_IMAGE = os.path.join(SAMPLE_FOLDER, "horse.png")
    CAR_IMAGE = os.path.join(SAMPLE_FOLDER, "car.png")
    assert os.path.isfile(HORSE_IMAGE) and os.path.isfile(CAR_IMAGE)
    
    # Acquire email account username

    username = input("Enter username: ")

    # The program uses Gmail as the default host.

    service = mailupdater.Service(username)

    # Send one email.

    with service.create("Hello world") as email1:
        email1.write("Python is great for sending emails.")

    # Send another email.

    with service.create("GANs can generate this horse") as email2:

        email2.write('''Hello!

        These images of a horse
        and a car are actually
        generated by a GAN 
        called ChainGAN. It
        was trained on CIFAR10.
        ''')

        email2.attach(HORSE_IMAGE)
        email2.attach(CAR_IMAGE)

        # Writing to the email multiple times is supported.

        email2.write("Please enjoy it.")
        email2.write("Regards,\n\nMr. Onion\n")
        
    # Sending emails to multiple people
    
    recipients = list(map(str.strip, input("Enter recipients (comma-separated): ").split(",")))
    
    service = mailupdater.Service(username, recipients)
    
    with service.create("Party invitation") as email3:
        email3.write("Come to my party!")

if __name__ == "__main__":
    main()
