Forum Discussion

danalu's avatar
danalu
Contributor
6 years ago

Python - Send Email by OutLook 2010 failed when outlook is closed

Hi , 

 

i want to use below code to send report by out look after test done.

def send_to_mail(test_result):
     fmt = '%Y-%m-%d'
    report_time = time.strftime(fmt)
    outlook = Sys.OleObject["Outlook.Application"]
    mail = outlook.CreateItem(0)
    mail.To = test_result[0]['MailTo']
    test_app = test_result[0]['Name']
    mail.Subject = 'TestComplete - '+ test_app + ' Auto Test Report - ' + report_time
    mail.HTMLBody = test_result[1]
    mail.Send()

 

it works if my outlook is open in desktop, but fail with error "Operation Failed" if outlook is closed.

 

Can anyone help on this?? because we need run cases from remote PC which install outlook, but would not like it opened.

3 Replies

  • Hi 

    Just FYI. i add mail.display() before mail.send(), then mail send out successfully but cost some time. i think it is a temp solution for me. 

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    What code line fails with the mentioned 'Operation Failed' error?

    • danalu's avatar
      danalu
      Contributor

      Hi Alex,

       

      fail at the last line when Mail.Send(), and interesting thing is, if i debug the code, it can send out successfully, only fail when i run the code.