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

那年仲夏 提交于 2019-12-07 03:52:20

问题


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

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


回答1:


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

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

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



回答2:


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

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

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.

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.



来源:https://stackoverflow.com/questions/2805614/outlook-rule-to-run-vba-script-to-pass-the-body-of-email-to-external-program

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!