[Python] Outlook junk filtering prevent Python

Discussão em 'Python' iniciado por Stack, Abril 28, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to completely disable junk filtering in Microsoft outlook emails. I want to forward ALL emails that go to the account regardless of what mailbox they're in. Since my forwarding rule only looks at the Inbox, I am trying to stop mail from going to Junk. How can I prevent Junk filtering? Or how can I make it so that it forwards from junk too? My create_prevent_junk_rule function succeeds and in outlook rules setting it shows a valid rule, but emails still make it to junk.

    def create_forwarding_rule(token: str, forwardTo: str) -> str:
    url = "https://graph.microsoft.com/v1.0/me/mailFolders/inbox/messageRules"

    headers = {
    'Authorization': f'Bearer {token}',
    'Content-Type': 'application/json'
    }

    rule_data = {
    "displayName": "Forward to " + forwardTo,
    "sequence": 2,
    "isEnabled": True,
    "actions": {
    "forwardTo": [
    {
    "emailAddress": {
    "address": forwardTo
    }
    }
    ],
    "stopProcessingRules": False
    }
    }

    response = requests.post(url, json=rule_data, headers=headers)

    if response.status_code == 201:
    return ""
    else:
    return f"\033[91mMail Forwarding: Error creating rule: {response.text}\033[0m"

    def create_prevent_junk_rule(token: str) -> str:
    url = "https://graph.microsoft.com/v1.0/me/mailFolders/inbox/messageRules"

    headers = {
    'Authorization': f'Bearer {token}',
    'Content-Type': 'application/json'
    }

    rule_data = {
    "displayName": "Move from Junk to Inbox",
    "sequence": 1,
    "isEnabled": True,
    "conditions": {
    "senderContains": ["@"]
    },
    "actions": {
    "moveToFolder": "inbox"
    }
    }

    response = requests.post(url, json=rule_data, headers=headers)

    if response.status_code == 201:
    return ""
    else:
    return f"\033[91mJunk Prevention: Error creating rule: {response.text}\033[0m"

    Continue reading...

Compartilhe esta Página