Automated outlook email forwarding with python for automated batching

ChatGPT

1. Background:

The outlook mailbox does not allow more than one email to be forwarded, so if I have 10,000 emails, wouldn’t I need to forward them one by one.😨

So I decided to write code in python to implement automatic mail forwarding. 👀

2. How many ways to achieve that?:

· Use web version of outlook to capture emails and buttons in web pages for automated clicking

· Mouse and keyboard automation using client outlook mailboxes

 

3. I’ve tried those two ways, so I decided to use client outlook:

Download the standard compilers for Python. Here I am using Pycharm CE.

Install third party libraries and packages required for mouse and keyboard automation. 

There are many third party libraries that may be used here, you don’t need to install them all, the recommended one is: Pyautogui

				
					pip3 install pyautogui
				
			
4. Using ChatGPT to generate code:

Breaking down your requirements, I would put the prompt in the code box below.

 

Please help me write a piece of code that uses python code to control the mouse and keyboard to implement automatic mail forwarding in the outlook programme of a MacBook.

ChatGPT prompt
				
					import time
import pyautogui

def forward_emails():
    # 等待 Outlook for Mac 打开
    time.sleep(5)

    # 使用 PyAutoGUI 来模拟鼠标点击和键盘操作
    pyautogui.click(100, 100)  # 点击 Outlook for Mac 应用图标

    # 等待 Outlook for Mac 打开
    time.sleep(10)

    # 循环转发前10封邮件
    for i in range(1, 11):
        try:
            # 选择邮件(根据实际位置和分辨率进行调整)
            pyautogui.click(300, 200 + 40 * (i - 1))

            # 打开转发菜单(根据实际位置和分辨率进行调整)
            pyautogui.click(800, 200)

            # 点击 "转发" 选项(根据实际位置和分辨率进行调整)
            pyautogui.click(900, 300)

            # 输入转发邮箱地址(根据实际位置和分辨率进行调整)
            pyautogui.write("Y.Tu2@outlook.com")

            # 发送邮件(根据实际位置和分辨率进行调整)
            pyautogui.press('enter')

            print(f"邮件{i} 转发成功")

        except Exception as e:
            print(f"邮件{i} 转发失败,错误信息:{str(e)}")

        # 等待一段时间,确保邮件转发完成
        time.sleep(2)

if __name__ == "__main__":
    forward_emails()

				
			

You can add any code you need according to the real application.

5. Developing your code:

If you want to realize more functions, try adding some requirements based on the original prompt.

In practice, it is necessary to adjust the parameters and positions according to the position of the buttons, etc., and the operation of the software.

 

				
					outlookmport time
import pyautogui

def forward_emails():
    # 等待 Outlook for Mac 打开
    time.sleep(5)



    # 等待 Outlook for Mac 打开
    time.sleep(1)

    # 循环转发前10封邮件
    for i in range(1, 1000):
        try:

            # 打开转发菜单(根据实际位置和分辨率进行调整)
            pyautogui.click(555, 95)
            pyautogui.click(1000, 190)
            time.sleep(3)
            # 输入转发邮箱地址(根据实际位置和分辨率进行调整)
            pyautogui.write("Y.Tu2@outlook.com")
 
            # 发送邮件(根据实际位置和分辨率进行调整)
            pyautogui.press('enter')
            time.sleep(3)
            pyautogui.click(555, 95)
            time.sleep(5)
            pyautogui.click(390, 95)

            print(f"邮件{i} 转发成功")


        except Exception as e:
            print(f"邮件{i} 转发失败,错误信息:{str(e)}")

        # 等待一段时间,确保邮件转发完成
        time.sleep(2)

if __name__ == "__main__":
    forward_emails()

				
			

The keyboard and mouse control pyautogui can be used in many automation applications.

Scroll to Top