如何引用触发Outlook宏的邮件? [英] How to reference the mail which triggered the outlook macro?

查看:181
本文介绍了如何引用触发Outlook宏的邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设计一个QTP框架,自动化工程师可以在其中发送电子邮件以开始执行测试套件(可以使用MS Outlook安排电子邮件)

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)

收到触发邮件后,应立即下载附件,并使用Outlook宏的适当设置自动启动QTP

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

但是在上述情况下,我想下载邮件的附件并将邮件移到触发宏的其他文件夹中.

有什么方法可以引用触发宏的邮件?

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)在下面添加代码(更改为使用cscript.exe):

1) Add code below (altered to use cscript.exe):

Sub TestSuiteInitialilzer_Rules(ByRef oMail As MailItem)
    Const FileName = "C:\Email Attachments\"
    For Each Atmt In oMail.Attachments
        'Download the attachment
        Atmt.SaveAsFile FileName & Atmt.Filename
    Next Atmt
    ' Move the Mail to objDestFolder
    oMail.Move objDestFolder
    'launchQTP = "C:\Unlock.vbs"
    launchQTP = "cscript.exe //nologo C:\Unlock.vbs"
    Set objShell = CreateObject("WScript.Shell")
    'QTP will be launched with the neccassary configurations through the vb script
    objShell.Run launchQTP
    Set objShell = Nothing
End Sub

2)在现有邮件规则的顶部添加Outlook规则(对收到的邮件应用规则).最好关闭您现有的计算机.

2) Add Outlook Rule (Apply rule on messages I receive) on top of your existing one. Better to turn off your existing one.

这篇关于如何引用触发Outlook宏的邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆