How do I generate and open an Outlook email with Python (but do not send) How do I generate and open an Outlook email with Python (but do not send) python python

How do I generate and open an Outlook email with Python (but do not send)


Call mail.Display(True) instead of mail.send


tldr: Use mail.Display(False) instead of mail.Display(True)

mail.Display(False) will still display the window.If you use mail.Display(True) the scripts stops until the window is closed. So use mail.Display(False) this will open the window and your python script will move on to the next command. It is also useful to know that you can use mail.save() to save as draft in the draft folder.

Visit https://msdn.microsoft.com/en-us/VBA/Outlook-VBA/articles/mailitem-display-method-outlook to read more on this


I like the solution :) But I want to add some infos:

Using the solution, it is probably the best way to add a mail input with Html format for modification.

Also add the file from the working directory...

#requirements.txt add for py 3 -> pypiwin32def Emailer(text, subject, recipient):    import win32com.client as win32    import os    outlook = win32.Dispatch('outlook.application')    mail = outlook.CreateItem(0)    mail.To = recipient    mail.Subject = subject    mail.HtmlBody = text    ###    attachment1 = os.getcwd() +"\\file.ini"    mail.Attachments.Add(attachment1)    ###    mail.Display(True)MailSubject= "Auto test mail"MailInput="""#html code here"""MailAdress="person1@gmail.com;person2@corp1.com"Emailer(MailInput, MailSubject, MailAdress ) #that open a new outlook mail even outlook closed.