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

wnnmaw picture wnnmaw · Jan 6, 2014 · Viewed 36.4k times · Source

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

Answer

Dmitry Streblechenko picture Dmitry Streblechenko · Jan 6, 2014

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