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.