[Python] Unable to Send Emails Via Python for Shared Inbox

Discussão em 'Python' iniciado por Stack, Junho 5, 2025.

  1. Stack

    Stack Membro Participativo

    I'm an azure admin trying to setup a Shared Inbox for a project where we'll be notifying our remote locations of upcoming hardware changes, and to ensure they are prepared to receive and install the equipment. I've been able to send emails from the Shared Inbox manually but looking to streamline the process as we are ramping up to hundreds of emails a week. Going through a lot of googling I'm using this basic structure to try and confirm I can make this work:

    import win32com.client as win32

    outlook = win32.Dispatch("Outlook.Application")
    mail = outlook.CreateItem(0)
    mail.To = "myemail@company.com"
    mail.CC = ""
    mail.Subject = 'New Hardware'
    mail.Body = "Hello,.."

    mail.SentOnBehalfOfName = "sharedinbox@company.com"

    mail.Send()


    I've confirmed this works when using my email and another shared inbox that was setup for a different project, but still having issues with the newly created shared inbox. When the code is ran I'll get a System Administrator email saying "Undeliverable." Viewing this message in new Outlook doesn't provide details but when viewing in classic Outlook it states I don't have "permission to send the message on behalf of the specified user".

    Looking in Azure I've confirmed the account is enabled, and looking in Exchange I've confirmed myself to be a "Send as" and "Read and Manage" delegate. This persists even after removing myself from the delegation, waiting 30 minutes, then re-adding myself.

    Comparing the shared inbox to the shared inbox that is working I'm unable to find any differences in configuration in azure or exchange, the only thing that the non-working inbox had was it was a Distro list before I deleted and re-created it as a shared inbox.

    Other thing to note is that when looking up connected accounts using

    mapi = outlook.GetNamespace("MAPI")

    for x in mapi.Accounts:
    print(x)


    only my email shows up here. My coworker who is doing the automated messages from the working shared inbox gets the same results as myself, and I've confirmed that we're running similar setups where we're not logged into either of the shared inbox's in Outlook, just added under "shared with me". A final thing to note is that I was able to send an email through the working shared inbox using the script above, making me think it's something to do with the new shared inbox somewhere.

    Continue reading...

Compartilhe esta Página