Forum Discussion

anirshar's avatar
Occasional Contributor
2 years ago

How to use CDO objects to send email with .mht file as body but not as attachment

I am using CDO as below, to email the output .mht file upon execution of project as an attachment

However I wish the contents of .mht file to be in email body. How can I do that?

def SendEmail(mFrom, mTo, mSubject, mBody, mAttach):
schema = ""
mConfig = Sys.OleObject["CDO.Configuration"]
mConfig.Fields.Item[schema + "sendusing"] = 2
mConfig.Fields.Item[schema + "smtpserver"] = ""
mConfig.Fields.Item[schema + "smtpserverport"] = 25
mMessage = Sys.OleObject["CDO.Message"]
mMessage.Configuration = mConfig;
mMessage.From = ""
mMessage.To = ""
mMessage.Subject = "Subject"
mMessage.HTMLBody = "Body"
except Exception as e:
Log.Error("E-mail cannot be sent", str(e))
return False
Log.Message("Message was sent successfully to")
return True 

7 Replies

  • rraghvani's avatar
    Champion Level 3

    You will need to set MIME header fields, MIME-Version, Content-Type etc. similar to what you have already done.

  • rraghvani's avatar
    Champion Level 3

    If it does not work, then it's not supported by CDO.


    A while back, I tried to attach the .mht Test Execution Summary to Outlook Office 365. After researching, I found out that Outlook does not support it.


    I have found an alternative way of sending results via email, using XML. I convert the XML results into HTML which looks like this,


    • AlexKaras's avatar
      Champion Level 3



      To add to rraghvani : internally, .mht is compressed set of web pages, scripts, etc. It might be that such content is prohibited to be sent as attachment in your system. Try to manually send e-mail with .mht attachment and talk to your system administrators depending on what result you will get.


  • rraghvani's avatar
    Champion Level 3

    You need to first verify whether your email system supports Multipurpose Internet Mail Extensions.