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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

.HTMLBody for sending emails thru Outlook

Status
Not open for further replies.

androidc

Programmer
May 27, 2003
13
CA
I've been working on a simple enough email procedure to send emails with outlook (see code below)

Now, i've actually gotten it to work. It was the first thing i got to work. Then i worked on the CCs and the attachments, which now also works fine. But the emails are not sending as HTML. it sends the code as straight text.
Wait, that's not quite right. It sends as straight text because i'm using .Body. But that's because now, when i use .HTMLBody, no text will send. Its just an empty email, with subject, attachments, cc, and a recipient.

I simply don't get it. Naturally, i've done something. But, if i use .HTMLBody, the email will have absolutely no text. Is there a step i'm missing?
according to faq184-1700, everything looks fine. faq184-766 does not mention sending HTML at all.

I tried CDO.Message examples, and they seem to send (ie no error occurs...) but i've never received a message sent with it. Besides, i'm supposed to use outlook. not my choice, but the purpose is to have our software work with MS Office as much as possible.

Thanks


PROCEDURE send_email
PARAMETERS cEmail, cSubject, cText, cCC, cCCi, cAttachments
LOCAL oOutlook, oNameSpace, oMessage, cHTML
#DEFINE olMailItem 0

oOutlook = CREATEOBJECT( "Outlook.Application" )
oNameSpace = oOutlook.GetNameSpace( "MAPI" )
oMessage = oOutlook.CreateItem( olMailItem )

WITH oMessage
.Subject = cSubject
cHTML = STRTRAN(cText, CHR(13) + CHR(10), &quot;<BR>&quot;)

**_body = eml_head.text + cText + eml_foot.text

.Body = cHTML && <--sends html as straight text
**.HTMLbody = _body && <-- sends nothing
** (..and not because the line concerning _body above is commented!!)

.Recipients.Add( ALLTRIM(cEmail) )
lResolved = .Recipients.ResolveAll()

.CC = cCC
.BCC = cCCi

.Attachments.Add( ALLTRIM(cAttachments) )
.Save()
.Send()
ENDWITH

oNamespace.Logoff

RETURN
 
but i've never received a message sent with it.

You weren't trying to send it to yourself were you? That doesn't work.

but the purpose is to have our software work with MS Office as much as possible.

CDO is a part of Microsoft Office, last I checked.

cHTML = STRTRAN(cText, CHR(13) + CHR(10), &quot;<BR>&quot;)

Can I assume that your cHTML contains the appropriate HTML tags?





Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Mike Gagnon:
I tried numerous email addresses. None received.
And i'm aware of CDO being a part of office, but it doesn't show the email to the user. which, as far as i'm concerned, should not be a problem but i've been told to use outlook...*shrug*
and yes, cHTML had proper html code. <html><body> etc. There was even a table.

MikeLewis:
You did not read the code properly. The comment character in foxpro is *. I'm aware that setting .Body flushes .HTMLBody and vice versa. I have both lines because .HTMLBody doesn't work. I would compile with .Body, test, see that it works (sends the html code as straight text). Then i would comment out .Body, try .HTMLBody without changing any other code, and the body of the email is empty. This is what i don't understand.


Thanks
 
I guess i should add that cText is basically a memo field where the user enters the body of a letter. What's added is a header and footer which contains the <html><body> and </body></html> tags, as well as a table, within which is the body of the letter. I could post the html code if someone deems that as necessary.

If the html code is not correct, and i use the .HTMLBody tag, will the email still send a body? or will it appear as a badly coded html page would, but still showing -some- text?

Oh, i suppose this might help..using windows xp, office xp and vfp 6.0.
 
Did you ever overcome this. I seem to be experiencing exactly the same with the .htmlbody tag i.e. blank messages and I to have removed my .body tag which was working and replaced it simply with

.htmlbody = &quot;<HTML><H2>My HTML page.</H2><BODY>My body.</BODY></HTML>&quot;

as per the FAQ on this.

I am using VFP6 and Outlook XP.

Someone mentions you cannot send to yourself. Is that with automation or with CDO (which is my next project!). If I send to anyone, I am simply looking at the email in my Outbox or SentItems box and assume I should see the HTML body regardless of who I am sending to.

If you have made any progress I would be keen to know what the problem was. Thanks

Paul Herschell
 
Just answered my own question I think. As a last resort I tried resetting .body before setting .htmlbody ie

.body = &quot;&quot;
.htmlbody = &quot;<HTML><H2>My HTML page.</H2><BODY>My body.</BODY></HTML>&quot;

This seemed to do the trick. No idea why as the mail item has just been created so I would thought that .body would have been initialised anyway.

Paul Herschell
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top