How to continuously monitor a new mail in outlook and unread mails of a specific folder in python

后端 未结 2 559
失恋的感觉
失恋的感觉 2020-12-17 04:34

I want to check for a particular sender email and process it automatically wherever it arrives

However, there may be some situation where my outlook was restarted, m

2条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-17 04:53

    Instead of monitoring outlook from python, try setting up outlook rules for that email and then launch python script via vba.

    Here is the code to launch the python script from VBA.

    Note: The code below was taken from here.

    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
    

    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

    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()
    

提交回复
热议问题