Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use outlook to create a Email from a formatted Word DOCX file and include attachments

Status
Not open for further replies.

SteveatPMP

Programmer
Jul 17, 2013
1
US
Hello
I am using VFP 9.0 and Outlook 2007 as well as word 2007 I need to automatically send an email that will put a word document in the body and attaches 3 files as attachments.
I have used code like this in the past
Start outlook
Local oappoutlook
oappoutlook = Createobject("Outlook.application")
* Get MAPI namespace
Local nmmapi
nmmapi = oappoutlook.getnamespace("MAPI")
* Create new message
* Fill in message Data
Select emailaddr
Go Top

Do While !Eof()
? Addr
Local lofolder,msg
lofolder = nmmapi.getdefaultfolder(4) && outbox
msg = lofolder.items.Add()
msg.recipients.Add(Addr) && Insert email address
msg.subject = csubject
msg.body = massmailconfig.emailmsg
*msg.body = (massmailmesg.docx)
msg.Send() && Send this message
Skip
Enddo

and this works, however I can get the msg.body to handle anything but plain text and I need to include formatted text, color, fonts and bolding.
Thank you
 
Can you put a word document in the body of an e-mail using Outlook? (Not with automation). I don't think so. It gets translated to HTML code when paste it into the body of the e-mail. So that is what you need HTML format.


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
ReFox XI (www.mcrgsoftware.com)
 
You could try something like this:

1. Use Automation to open the document in Word. Within Word, save it as an HTML documentent (using the SaveAs method).

2. Use FILETOSTR() to copy the HTML document to a variable.

3. In your Outlook Automation code, store the contents of the above variable in the HTMLBody propery of the mail item (rather than the Body property).

I've not tested this, but I think it should work.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Use FILETOSTR() to copy the HTML document to a variable.

Or if your DOCX file has some special formatting that you want to retain, use VFP Automation of Word to do a SaveAs.. of the DOCX file into an HTML Format which could then be used as the body of your Email.

Good Luck,
JRB-Bldr


 
Mike - Isn't that what I said?

Oops. Looks like I was in too big of a hurry this morning.
Sorry.

SteveatPMP - Good Luck,
JRB-Bldr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top