Outlook 2013 display HTML code instead of actual Data - windows

I am using win32com.client , python 2.7.x and outlook 2013 on windows platform.
I need to post contents of a HTML file to the body of outlook message.
I followed the posts here ,here and here about how to save excel as HTML and paste data within outlook.
However , when I read the file via win32com.client.Dispatch , instead of seeing message, I am seeing HTML code.
Here is the code that converts a processed xlsx file to html format using win32.com.
#Section to convert excel workbook to html
myfile = os.getcwd()+ "\\" + outfile
newfile = os.getcwd()+ "\\" + "emailData.html"
xl = EnsureDispatch('Excel.Application')
#xl.Visible = True
wb3 = xl.Workbooks.Open(myfile)
wb3WorkSheet = wb3.Worksheets(1)
wb3WorkSheet.Activate()
wb3.SaveAs(newfile, constants.xlHtml)
wb3.Close(True)
xl.Workbooks.Close()
xl.Quit()
del xl
The output of above is newfile which is basically an export of xlsx file saved as html. It is then opened via mail.body handler which should read and display actual contents within outlook.
Here is the code for that.
from win32com.client.gencache import EnsureDispatch
from win32com.client import constants, Dispatch
#Create and open mail message
def Emailer(text, subject, recipient):
outlook = Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = recipient
mail.Subject = subject
mail.HtmlBody = text
#mail.HtmlBody = open(newfile).read()
mail.body = open(newfile).read()
attachment1 = os.getcwd()+"//"+outfile
mail.Attachments.Add(attachment1)
mail.Display(True)
Emailer(pageTemplate,
"test subject",
"abc#yahoo.com"
)
So, when I open newfile (html file) using mail.body = open(newfile).read() it pastes html content within a new outlook email body.
When I open newfile (html file) using mail.HtmlBody = open(newfile).read() it's giving following error within outlook email body
ERROR: This page uses frames, but your browser doesn't support them.
Any ideas on this behavior?
I basically want to copy/paste html file (which is an export of xlsx) within outlook email.
Not sure if above is correct approach or there are other alternatives.
Is there a way to paste /render HTML frames into outlook email body?
Any pointers is appreciated.

You need to set the HTMLBody property, but keep in mind that HTML in Outlook is rendered by Word, not IE, and inline frames are not supported.

Related

encoding problem for SUBJECT of email using CDO

Using vbscript (asp) with CDO I have problem with encoding in SUBJECT of email. I have used two solutions for BODY part of email and both works but non of them works for SUBJECT part.
First solution: Endcoding characters of email BODY using chrw (not working for subject):
for x=1567 to 1785
encoded="&#" & x & ";"
Body= Replace(Body, chrw(x), encoded, 1, -1, 1)
next
Second solution: setting HTMLBodyPart encoding:
objMessage.HTMLBodyPart.Charset = "utf-8"
is there something similar for SUBJECT part of email (e.g. objMessage.SubjectPart.Charset)?
Try:
objMessage.TextBodyPart.Charset = "utf-8"
or simply:
objMessage.BodyPart.Charset = "utf-8"
It has been documented elsewhere that modifying the Charset of the TextBodyPart also impacts (the plain/text) Subject.
Hope this helps.

AppleScript - extract an email message as a MIME object

I have an AppleScript I wrote to do some parsing on Mail.app messages, however it seems I will need more powerful processing (specifically - separate a replied message from the original message it quotes) than what is provided by AppleScript (say, using Python's email package). Is it possible to get an email message as a MIME string?
I'm not sure if this is what you meant, but here is how you can get the raw message text from a selection you've made in Mail.app which can than be processed with MIME tools to extract all the parts.
tell application "Mail"
set msgs to selection
if length of msgs is not 0 then
repeat with msg in msgs
set messageSource to source of msg
set textFile to "/Users/harley/Desktop/foo.txt"
set myFile to open for access textFile with write permission
write messageSource to myFile
close access myFile
end repeat
end if
end tell
And then here's a Python email example script that unpacks the message and writes out each MIME part to a separate file in a directory
https://docs.python.org/3.4/library/email-examples.html
#!/usr/bin/env python3
"""Unpack a MIME message into a directory of files."""
import os
import sys
import email
import errno
import mimetypes
from argparse import ArgumentParser
def main():
parser = ArgumentParser(description="""\
Unpack a MIME message into a directory of files.
""")
parser.add_argument('-d', '--directory', required=True,
help="""Unpack the MIME message into the named
directory, which will be created if it doesn't already
exist.""")
parser.add_argument('msgfile')
args = parser.parse_args()
with open(args.msgfile) as fp:
msg = email.message_from_file(fp)
try:
os.mkdir(args.directory)
except FileExistsError:
pass
counter = 1
for part in msg.walk():
# multipart/* are just containers
if part.get_content_maintype() == 'multipart':
continue
# Applications should really sanitize the given filename so that an
# email message can't be used to overwrite important files
filename = part.get_filename()
if not filename:
ext = mimetypes.guess_extension(part.get_content_type())
if not ext:
# Use a generic bag-of-bits extension
ext = '.bin'
filename = 'part-%03d%s' % (counter, ext)
counter += 1
with open(os.path.join(args.directory, filename), 'wb') as fp:
fp.write(part.get_payload(decode=True))
if __name__ == '__main__':
main()
So then if the unpack.py script is run on the AppleScript output...
python unpack.py -d OUTPUT ./foo.txt
You get a directory with the MIME parts separated. When I run this on a message which quotes an original message then the original message shows up in a separate part.

Create and show a PDF file from a Lotus Notes action

I'm using an action inside a form to create a Word document, using the CreateObject("Word.application") method, then I modify it to my liking and save it in a temp directory.
I can show the Word document as soon as it is created by calling nameOfTheDocument.visible(true), and by modifying the Save action I can save the newly created document as a PDF, however I can't find a way to show it to the user.
Trying to call visible(true) on the PDF object results in error "Instance member VISIBLE does not exist"
Hmmm... The best and right way - use OS file association.
I'm use java way:
//Win
Process p = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + filePath);
p.waitFor();
//MacOS.*Nix
Process p = Runtime.getRuntime().exec("/usr/bin/open " + filePath);
p.waitFor();
But you can call this command on Lotusscript:
Shell({rundll32 url.dll,FileProtocolHandler } & fullFilePath,1)
'or
Shell({/usr/bin/open } & fullFilePath,1)
We have used the Shell command to launch PDFs in the past. Something like the below. The only downside to this is if the location of the executable changes (whether from upgrade or change to a different program) the code breaks.
Dim ProgPath$, FilePath$
Dim result As Integer
'Path of the executable
ProgPath$ = |"C:\Program Files (x86)\Adobe\Acrobat 7.0\Acrobat\Acrobat.exe"|
'Path of the file to open
FilePath$ = | "C:\TestFile.PDF"|
result = Shell(ProgPath$ & FilePath$,1)

MAPI Control Multiple attachments

I am trying to send an email with multiple attachments using the VB6 MAPIMessages control.
1) I am able to use this control to send a single attachment but it displays an error saying "Attachment not found", if I try to send more than one file.
2) I also need to suppress the warning message when I try to send an email
Any ideas?
Here's the code:
MAPISession1.SignOn
MAPIMessages1.SessionID = MAPISession1.SessionID
MAPIMessages1.Compose
MAPIMessages1.RecipDisplayName = "abbid_siddiqui#hotmail.com"
MAPIMessages1.MsgSubject = "MAPI subject with attachments"
MAPIMessages1.MsgNoteText = "This is atest"
MAPIMessages1.AttachmentIndex = 0
MAPIMessages1.AttachmentName = "test.csv"
MAPIMessages1.AttachmentPathName = "C:\test.csv"
MAPIMessages1.AttachmentIndex = 1
MAPIMessages1.AttachmentName = "holidays_2013.xls"
MAPIMessages1.AttachmentPathName = "E:\holidays_2013.xls"
MAPIMessages1.ResolveName
'Send the e-mail message to the Recipient
MAPIMessages1.Send
Try setting the AttachmentPosition property to the same value as the AttachmentIndex

How send mail with vbscript?

i need to send a file attached to an email that must be setn to specific user through smtp server with auth. How can i do that in vbscript?
Thanks.
You can just take a look here:
how to send an email with attachment in vb.net?
Try the following:
Dim oMsg As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage()
oMsg.From = "noone#nobody.com"
oMsg.To = "someone#somewhere.com"
oMsg.Subject = "Email with Attachment Demo"
oMsg.Body = "This is the main body of the email"
Dim oAttch As MailAttachment = New MailAttachment("C:\myattachment.zip")
oMsg.Attachments.Add(oAttch)
SmtpMail.Send(oMsg)
I have no experience with vbscript of VB for that matter... But a quick Google gave me this result - it looks simple enough.
I hope this helps :)

Resources