Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have a script that automatically creates and sends emails sends emails using the simple function below:

def Emailer(text, subject, recipient):     import win32com.client as win32         outlook = win32.Dispatch('outlook.application')     mail = outlook.CreateItem(0)     mail.To = recipient     mail.Subject = subject     mail.HtmlBody = text     mail.send 

But how do I open this email in an Outlook window so that it can be manually edited and sent?

Ideally, I'd like something like this:

def __Emailer(text, subject, recipient, auto=True):     import win32com.client as win32         outlook = win32.Dispatch('outlook.application')     mail = outlook.CreateItem(0)     mail.To = recipient     mail.Subject = subject     mail.HtmlBody = text     if auto:         mail.send     else:         mail.open # or whatever the correct code is 
like image 964
wnnmaw Avatar asked Jan 06 '14 18:01

wnnmaw


1 Answers

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

like image 141
Dmitry Streblechenko Avatar answered Oct 09 '22 06:10

Dmitry Streblechenko