Мои сценарии требуют отправки нескольких электронных писем с помощью клиента Outlook. Мне нужно создать код, который отлично работает в MacOS, но я застрял, когда пробую тот же код в системе Windows. В macOS я использую Osascript, который отлично работает. Я ищу альтернативы osascript для систем Windows. Вот рабочий код в macOS:
email = input («Вы хотите отправить тестовые электронные письма на test1 и test2? (Y / n):»)
if email == "y":
with open("address.txt", "w+") as fp:
for x in domains:
test1 = "test1@",x,("\n")
test1 = "".join(test1)
fp.write(test1)
print("An email will be sent to: ",test1,end='')
post = "test2@",x,("\n")
post = "".join(post)
fp.write(post)
print("An email will be sent to: ",post,end='')
fp.close()
with open("address.txt", 'r') as f:
data = f.read()
with open("address.txt", 'w') as w:
w.write(data[:-1])
os.system("""osascript -e 'tell application "Microsoft Outlook"
set srcFile to("address.txt")
set lns to paragraphs of (read srcFile as «class utf8»)
repeat with ln in lns
set the clipboard to ln
set theMessage to make new outgoing message with properties {subject:"this is a test"}
make new recipient with properties {email address:{address:ln}} at end of to recipients of theMessage
send theMessage
end repeat
end tell' """)
print(len(open("address.txt").readlines()),"e-mails have been sent")
else:
print("No e-mails will be sent")
selection = input("Would you like to return to the main menu? y/n ")
if selection == "y":
os.system("clear && python3 script.py")
else:
quit
FYI - в файле address.txt предварительно определен домен, куда я хотел бы отправлять электронные письма.