Skip to content

oliverm91/easy_outlook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Only tested in few artificial cases. Never in real processes

easy_outlook

Wrapper of win32com library for easier use.

Install instructions:

If git is installed: pip install git+https://github.com/oliverm91/easy_outlook.git@main

Else, build a whl with python setup.py bdist_wheel. The whl file will be in a new generated dist/ folder. Then, install the whl file in dist/ folder with pip as pip install bdist/whlfilename.whl

Examples

Find, download attachment and reply mail

outlook_root_folder_must_contain = 'NameOfOutlookRootFolder' # Sometimes is own mail like [email protected]
hndlr = OutlookHandler(outlook_root_folder_must_contain)
found_mails_must_contain_in_subject = 'ABC Report'

# Get dict of folderName: list[ReceivedMail, ReceivedMail, ...]
received_mails_dict = hndlr.get_emails_by_subject(found_mails_must_contain_in_subject, exact_date=date.today(), search_in_inbox=True)

#Iter
for received_mails in received_mails_dict.values():
    for received_mail in received_mails:
        print('Downloading attachments')
        for attachment in received_mail.attachments:
            print(attachment.filename, attachment.size)
            attachment.save('some_path', 'filename.ext')
        print(f'Replying to {received_mail.sender}')
        received_mail.reply_all('This is the reply', extra_copy_recipients=['[email protected]'], attachment_paths=[os.path.join(path, 'test.txt')])

Send mail with many recipients, CC and attachments

nm = NewMail(['[email protected]', '[email protected]'], subject=subject, body='ABC', attachment_path=os.path.join(path, 'test1.txt'))
nm.add_recipient('[email protected]')
nm.add_copy_recipient('[email protected]')
nm.add_attachment_path(os.path.join(path, 'test2.txt'))
nm.send()

About

Python win32com Outlook wrapper

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages