pyrg
pyrg

Reputation: 3

Is it possible to include a hyperlink in a non-html (outlook) email on python?

I am trying to send emails from outlook using a python script. If I do something like this:

import win32com.client as win32
outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = '[email protected]'
mail.Subject = 'Python test'
mail.Body = 'This is the bodyyyy'
mail.send()

Everything runs smooth and the recipient gets the email. The problem comes when I try to either format the text (bold, underlined,...), include hyperlinks or substitute strings (with .format()). I haven't found a way to do that without creating a monster - insane amount of {{{{asduf}asdf.a()}]]{}}{{}) and so on.

So, is there a way to, in the format I wrote above, send an email including hyperlinks, text formatting and string substitution?

I haven't found an answer to this specific question and I apologize if it looks too simple for you, I'm just a newbie trying to do newbie stuff.

Thanks and cheers!

Upvotes: 0

Views: 651

Answers (1)

Dmitry Streblechenko
Dmitry Streblechenko

Reputation: 66276

Instead of setting the plain text Body property, set the HTMLBody property to a properly formatted HTML (links and all).

Upvotes: 1

Related Questions