Edoardo Maschio
Edoardo Maschio

Reputation: 63

How can I print html text with python using variables?

I need to print an HTML text within an email using python and taking values from variables.

I tried using the following, but in the htmlbody section it returns an error, and it appears to only be working when I type everything as a string, but I need to be able to make a reference to variables

import win32com.client
from win32com.client import Dispatch, constants
testo="Edoardo!!!"
const=win32com.client.constants
olMailItem = 0x0
obj = win32com.client.Dispatch("Outlook.Application")
newMail = obj.CreateItem(olMailItem)
newMail.Subject = "Test !!"
newMail.HTMLBody = ("Some text here<u>",---variable here---,"</u>Othertext")
newMail.To = "[email protected]"

What can I do? Thank you in advance

Upvotes: 1

Views: 743

Answers (1)

Swagga Ting
Swagga Ting

Reputation: 602

You are trying to pass a tuple and not a string. You could use the following instead:

newmail.HTMLBody = "Some text here<u>{var}</u>Othertext".format(var=a)

Another way is to use the + sign:

newmail.HTMLBody = "Some text here<u>" + a + "Othertext"

Upvotes: 1

Related Questions