Created
December 19, 2024 05:43
-
-
Save exemplum100/4170dd679d7dc64349fc572df4173e71 to your computer and use it in GitHub Desktop.
Пример использования py с Outlook (архивирование)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import shutil | |
import pprint | |
from datetime import datetime | |
import win32com.client as win32 | |
#upd stamp | |
with open("lastupd.txt", "a") as f: | |
x = datetime.today().strftime('%Y-%m-%d %H:%M:%S') | |
f.write(x + '\n') | |
f.close | |
#del old dir from copy stage | |
try: | |
shutil.rmtree('./DescArc') | |
except: | |
pass | |
#Copy dir (from updir/to current folder) | |
shutil.copytree('../PyDir', './DescArc') | |
print('\nAFTER:') | |
pprint.pprint(os.listdir('./DescArc')) | |
#zip it! | |
shutil.make_archive('DescSendArc', 'zip', 'DescArc') | |
# send it! | |
olApp = win32.Dispatch('Outlook.Application') | |
olNS = olApp.GetNameSpace('MAPI') # NameSpaces need for attchm | |
subj1='DescArc [' + datetime.today().strftime('%Y-%m-%d %H:%M:%S')+']' | |
body1 = str(os.listdir('./DescArc')) | |
mailItem = olApp.CreateItem(0) | |
mailItem.Subject = subj1 | |
mailItem.BodyFormat = 1 | |
mailItem.Body = body1 | |
mailItem.To = '@gmail.com' #may blocked some attachments or mark as spam | |
mailItem.Attachments.Add(os.path.join(os.getcwd(), 'DescSendArc.zip')) | |
mailItem.Send() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment