Issue
Im just trying to automate an outlook mail with python. Im struggling a bit with a probably very small issue but still cannot find a solution so far.
I actually just want to display my listvalues in this html formatted emailbody as a normal list. That means vertically with linebreak - lika an enumeration.
The list can be dynamic. So there can be also more than 4 list_values. This is my code so far. Is there anybody who can help me with an approach/solution. Thanks in advance Best regards Sascha
import win32com.client as win32
list = ["dog","cat","mouse","monkey"]
outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = "me@test.com"
mail.CC = "me@test.com"
mail.Subject = f'Test'
mail.HTMLBody = f"<p>This is my test_list:</p><br>"
mail.Display()
Solution
You can join the items of the list with a <br> (line break) element :
import win32com.client as win32
a_list = ["dog", "cat", "mouse", "monkey"]
outlook = win32.Dispatch("outlook.application")
mail = outlook.CreateItem(0)
mail.To = "me@test.com"
mail.CC = "me@test.com"
mail.Subject = 'Test'
mail.HTMLBody = f"<p>This is my test_list:<br>{'<br>'.join(a_list)}</p>"
mail.Display()
Answered By - Timeless

0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.