-2

I am reading .txt file in Python code and I should get the same mail body what I have in my text file. It is working fine but hyperlinks not displayed in my outlook email, it displays only as text in outlook email.

Below is the code:

Mail_Content = open("MailBody.txt","r")
    Read_Content = Mail_Content.read()

In the text file , passing content like this for hyperlink:

<a href="link">linkname</a>,'html'

Please help me out, I am trying to fix this from last two days.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
Shruthi
  • 1
  • 2

2 Answers2

0

Firstly, you really need to show the code that sets the message body. Secondly, make sure you set the MailItem.HTMLBody rather than the plaintext MailItem.Body.

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
0

Make sure the BodyFormat property is set up correctly before setting the HTMLBody property in the code, for example, here is a VBA sample which shows how to set up it properly:

Sub CreateHTMLMail() 
 'Creates a new email item and modifies its properties. 
 Dim objMail As MailItem 
 'Create mail item 
 Set objMail = Application.CreateItem(olMailItem) 
 With objMail 
   'Set body format to HTML 
   .BodyFormat = olFormatHTML 
   .HTMLBody = "<HTML><H2>The body of this message will appear in HTML.</H2><BODY>Type the message text here. </BODY></HTML>" 
   .Display 
 End With 
End Sub
Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45