<p>不要从python监视outlook,尝试为该电子邮件设置outlook规则,然后通过vba启动python脚本。</p>
<p>下面是从VBA启动python脚本的代码。</p>
<p><em><strong>注意:</strong>下面的代码取自<a href="https://community.spiceworks.com/scripts/show/3851-vba-script-to-launch-python-script-in-outlook" rel="nofollow noreferrer">here</a>。</em></p>
<blockquote>
<pre class="lang-py prettyprint-override"><code>Sub UruchomBata(MyMail As MailItem)
Dim Ret_Val
Dim args As String
args = "c:\new.py"
Ret_Val = Shell("C:\python27\python.exe" & " " & args, vbNormalFocus)
End Sub
</code></pre>
<p>Below this line is the python script for those interested. It is
currently set to control the DTR pins on the com1 serial port. The
following will need to be save as a yourname.py file</p>
<pre class="lang-py prettyprint-override"><code>import serial
from time import sleep
conn = serial.Serial('com1',
baudrate=9600,
bytesize=serial.EIGHTBITS,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
timeout=1,
xonxoff=0,
rtscts=0
)
# Wake Modem
conn.setDTR(True)
sleep(3)
conn.setDTR(False)
sleep(1)
conn.close()
# Start talking
try:
while True:
conn.write('AT'+chr(13));
print conn.readline() # readlines() will probably never return.
finally:
conn.close()
</code></pre>
</blockquote>