0

I am using the win32com.client to send Outlook bulk emails via Python. Everything works. One thing that is missing in my code is a solution to choose the Titus classification. I have to click the popup manually.

Code snippet:

# Import modules
import pandas as pd
import win32com.client


# Prepare email send to loop through
def send_mail(email_address: str, title: str, html_body: str):
    """
    Use email object and fill it with parameters
    @params:
        email_address   - Required  : current email of primary contact (Str)
        title           - Required  : title of email bulk (Str)
        html_body       - Required  : body of email in html form (Str)
    """
    # Set up email content
    mail.To = email_address
    mail.Subject = title
    mail.HTMLBody = html_body

    # Send
    mail.Send()


# Initialize Outlook
outlook = win32com.client.Dispatch("outlook.application")

# Loop through email list
for idx, _ in enumerate(email_list["firstname"]):

    # Create E-mail object
    mail = outlook.CreateItem(0)

    # Items which change each loop
    email = email_list["email"].iloc[idx]
    firstname = email_list["firstname"].iloc[idx]
    html_body_filled = html_body_var.format(firstname=firstname)

    # Actual send function
    send_mail(email_address=email, title=title_var, html_body=html_body_filled)

There is a related question to mine: Python send outlook email with TITUS classification. However I could not make this solution work. If I adjust my code to:

    # Set up email content
    mail.To = email_address
    mail.Subject = title
    mail.HTMLBody = html_body

    # Add Titus classification
    mail.UserProperties = mail.UserProperties.Add("MY CLASSIFICATION", 1)
    mail.UserProperties.Value = "For internal use only"

    # Send
    mail.Send()

This resolves in the error "AttributeError: Property 'CreateItem.UserProperties' can not be set." in the first line of the added code.

Are the commands wrong, or can it also be my classification settings?

I do not want to turn the Titus classification of. However automating the selection when the popup appears, would be fine too.

Jeremy S.
  • 79
  • 6
  • I tried a little bit more: `mail.UserProperties.Add("Titus Classification", 1) mail.UserProperties.Item("Titus Classification").Value =` The error is gone, but the popup still appears. – Jeremy S. Aug 24 '22 at 08:44
  • `UserProperties.Add` returns the new `UserProperty` object, there is no need to retrieve it using again `UserProperties.Item`. I know nothing about Titus Classification, but what makes you think adding that property is all it takes? Take a look at an existing message in the Sent Items folder with the classification set with OutlookSpy (https://www.dimastr.com/outspy, I am its author - click IMessage button). Do you see any Titus specific properties? – Dmitry Streblechenko Aug 24 '22 at 21:29

0 Answers0