anirshar
2 years agoOccasional Contributor
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):
try:
schema = "http://schemas.microsoft.com/cdo/configuration/"
mConfig = Sys.OleObject["CDO.Configuration"]
mConfig.Fields.Item[schema + "sendusing"] = 2
mConfig.Fields.Item[schema + "smtpserver"] = "something.com"
mConfig.Fields.Item[schema + "smtpserverport"] = 25
mConfig.Fields.Update();
mMessage = Sys.OleObject["CDO.Message"]
mMessage.Configuration = mConfig;
mMessage.From = "someone@somewhere.com"
mMessage.To = "anotherone@somewhere.com"
mMessage.Subject = "Subject"
mMessage.HTMLBody = "Body"
mMessage.AddAttachment("file:///C:/Report.mht")
mMessage.Attachments.Item[1].ContentMediaType="application/octet-stream"
mMessage.Send();
except Exception as e:
Log.Error("E-mail cannot be sent", str(e))
return False
Log.Message("Message was sent successfully to anotherone@somewhere.com")
return True