Forum Discussion

vondie's avatar
vondie
Contributor
9 years ago

Wildcard Not Recognized in URL within an Email

Currently using TC 11.20 and writing scripts using Python. I am working on a script that checks the body content of my last email in my inbox (Outlook).  My end goal is to click a URL within an email...
  • vondie's avatar
    vondie
    9 years ago

    Thank you both for your input! I decided to follow a little of both pieces of advice and developed the solution below. 

     

    def check_email():
      msOutlook = Sys.OleObject["Outlook.Application"]
      
      mapi = msOutlook.GetNamespace("MAPI")
      
      inbox = mapi.Folders("test@test.com").Folders("Inbox")
      
      messages = inbox.Items
      message = messages.getLast()
      body_content = str(message.body)
    
      s = 'http://qaapps.test.com:12345/test/admin/password-reset/'
      
      time.sleep(10)
    
      if s in body_content:
       url = body_content[237:347] 
     
       Browsers.Item[btFirefox].Run(url)
       
       Log.Message("Test passed!") 
          
      else:
         Log.Message("Email not received. Please open bug in JIRA.")