Outlook 规则运行 VBA 脚本将电子邮件正文传递给外部程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2805614/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 11:37:02  来源:igfitidea点击:

Outlook rule to run VBA script to pass the body of email to external program

emailvbashelloutlookrule

提问by dshin

I've set up an Outlook rule that filters emails. I want to run an external program (python script) to parse each such email.

我已经设置了一个过滤电子邮件的 Outlook 规则。我想运行一个外部程序(python 脚本)来解析每个这样的电子邮件。

I know of the SHELL function, but I need a way to pass the body of the email to my external program.

我知道 SHELL 函数,但我需要一种方法将电子邮件正文传递给我的外部程序。

回答by wonderfulthunk

Google is your friend for this one, I got this snippet by searching "outlook vba script".

谷歌是你的朋友,我通过搜索“outlook vba script”得到了这个片段。

Basically for the body of the email you want to pass Item.Body to your python script.

基本上对于您想要将 Item.Body 传递给您的 python 脚本的电子邮件正文。

http://support.microsoft.com/kb/306108

http://support.microsoft.com/kb/306108

Sub CustomMailMessageRule(Item As Outlook.MailItem)
    MsgBox "Mail message arrived: " & Item.Subject
End Sub`

Sub CustomMeetingRequestRule(Item As Outlook.MeetingItem)
    MsgBox "Meeting request arrived: " & Item.Subject
End Sub

回答by heycooldude

You'd need a VBA script to parse python in outlook.

您需要一个 VBA 脚本来解析 Outlook 中的 python。

Press alt+F11. You will get a VBA window.

按 Alt+F11。您将获得一个 VBA 窗口。

Sub python(Item As Outlook.MailItem)
Shell ("python C:\path\tp\your\filename.py")
End Sub

I hope you have set windows variable path for python.

我希望你已经为 python 设置了 windows 变量路径。

Shell command passes the command to windows shell prompt. You can test this by running your python script in command prompt. If it is working there, then it should work here as well.

Shell 命令将命令传递给 windows shell 提示符。您可以通过在命令提示符下运行您的 python 脚本来测试这一点。如果它在那里工作,那么它也应该在这里工作。