Warm tip: This article is reproduced from serverfault.com, please click

How to add an olText UserProperty to an email

发布于 2020-12-02 09:24:46

I am trying to add a UserProperty to an email using win32com. The UserPropertyType should be set to 'olText'.

For the record, the name of the UserProperty ('NewDomain') is already a member of the collection of Outlook UserProperties.

I have tried the following:

import win32com.client as w32c
outlook=w32c.Dispatch('Outlook.Application').GetNameSpace('MAPI')
inbox=outlook.GetDefaultFolder(6)
emails=inbox.Items
email=emails.GetLast()
email.UserProperties.Add("NewDomain",UserPropertyType='olText',True)

I got the following error: TypeError: Add() got an unexpected keyword argument 'OlUserPropertyType'

The code works well in VBA with the syntax: email.UserProperties.Add("NewDomain", olText, True)

Many thanks for you help!

Questioner
Twin
Viewed
0
Dmitry Streblechenko 2020-12-03 00:11:10

UserPropertyType argument is an enum (int), not a string. olText is 1, so your code must be

email.UserProperties.Add("NewDomain", 1, True)