I'm using the exchangelib python EWS library to send emails. Sending from my mailbox works as expected but how can I send an email from a distribution list I have "Send As" permissions already applied (Have tested in Outlook changing the from address)?
The below code snippet will send the email but "me@domain.com" account shows as the sender. If I change "access_type=DELEGATE" to "access_type=IMPERSONATION", I receive an error "ErrorNonExistentMailbox: The SMTP address has no mailbox associated with it.".
credentials = Credentials("me@domain.com", password)
config = Configuration(server=server, credentials=credentials)
account = Account(primary_smtp_address="distlist@domain.com", config=config, autodiscover=False, access_type=DELEGATE)
message = Message(account=account,subject="subject",folder=None)
message.sender = "distlist@domain.com"
message.to_recipients = "me@domain.com"
message.body = "test"
message.send(save_copy=False, copy_to_folder=False)
Any help or guidance is very much appreciated
A distribution list usually doesn't have its own mailbox in Exchange, so you can't use its email address as primary_smtp_address
for the account.
Messages have both a sender
and an author
field. You could try to set the distribution list email in the author
field. Then emails may show up as coming from that email address.