Editing outlook distribution list using python

2.4k Views Asked by At

Anyone has any idea about how to edit the outlook distribution list using python? I tried SMTP and IMAP lib in python but basically it can send and receive the emails from an excel I need to get member from Excel and update it to outlook DL.

2

There are 2 best solutions below

1
On

Here is how you can access "Distribution List" from win32com

import win32com.client
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
address_lists = outlook.AddressLists
dls = address_lists['All Distribution Lists']
1
On

You can to use with win32com.client package and control to your Outlook application, for example:

import win32com.client
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
address_lists = outlook.AddressLists
contacts = address_lists['Global Address List']
contacts.AddressEntries.Add()  # to add contact TODO

first = contacts.AddressEntries.GetFirst()
first.Update()  # to update contact TODO
first.Delete()  # to delete contact

see also outlook AddressEntries doc and outlook AddressEntry doc