I am designing a QTP framework which in which the automation engineer sends an email in order to start the test suite execution (The email can be scheduled using MS Outlook)
As soon as the trigger mail is received, the attachment should be downloaded and QTP should be launched (automatically) using appropriate settings by the Outlook Macro
But in the above scenario I want to download the attachment of the mail and move the mail to a different folder which triggered the macro.
Is there any way to reference the mail which triggered the macro?
Currently this is what I am doing.
Sub TestSuiteInitialilzer(mail As Outlook.MailItem)
Set ns = Application.GetNamespace("MAPI")
Set Inbox = ns.GetDefaultFolder(olFolderInbox)
Set objDestFolder = Inbox.Folders("RAN")
FileName = "C:\Email Attachments\" & mail.Attachments.Item.FileName
'Download the attachment
Atmt.SaveAsFile FileName
'Move the mail to another folder
mail.Move objDestFolder
launchQTP = "C:\Unlock.vbs"
Set objShell = CreateObject("WScript.Shell")
‘Launch QTP
objShell.Run launchQTP
objShell = Nothing
End Sub
Two steps to skip checking the whole Inbox until a match. Keep yours just in case you need to run it manually for the first matching item.
1) Add code below (altered to use cscript.exe):
2) Add Outlook Rule (Apply rule on messages I receive) on top of your existing one. Better to turn off your existing one.
You just need to define a VBA macro sub which accepts a MailItem as a parameter. The source object will be passed to the sub and you don't need to search it in the Inbox folder. For example:
You can access attachments using the Attachments property of the MailItem class. The Move method allows to move the item to another folder.