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

cdo and font size/type 1

Status
Not open for further replies.

foxup

Programmer
Dec 14, 2010
328
CA
Hi All,

I have code below that works perfectly. I would simply need to change the "FONT TYPE & FONT SIZE" of the body of the email body being sent.

Here is my code:

has_txt=.F.
LOCAL iMsg,iConf
DECLARE SHORT InternetGetConnectedState IN wininet.DLL;
INTEGER @lpdwFlags, INTEGER dwReserved
lConnect=displayState()
IF lConnect
iMsg = CREATEOBJECT("CDO.Message")
iConf = CREATEOBJECT("CDO.Configuration")
Flds = iConf.FIELDS
WITH Flds
.ITEM(" = jhjjj
.ITEM(" = jjjjjj
.ITEM(" = jjjjjjj
.UPDATE()
ENDWITH
WITH iMsg
.Configuration = iConf
.TO = me
.BCC = ""
.FROM = "yiu"
.Subject = "dfgfdsgsdfgdfsgsdg"
.FIELDS("Priority").VALUE = 0 && -1=Low, 0=Normal, 1=High
.FIELDS.UPDATE()
IF has_txt=.F. && HAS ONLY PDF (NO TXT FILE EXISTS)
bod="<img src='cid:logo.png'><BR>Bonjour / Hello,<BR><BR>Ci-joint votre facture électronique pour le mois courant en format PDF.<BR>"
bod=bod+"Si vous avez besoin d'une autre copie, il est également disponible en ligne.<BR>"
bod=bod+"Pour y accéder, s'il vous plaît pointer votre navigateur au: "
bod=bod+"<BR><BR>nom d'utilisateur / username: "+"<BR><BR><BR>Merci / Thank You<BR><BR><BR>"
.HTMLBody = "font size=10 face=verdana>"
.HtmlBody=bod
ENDIF
.AddAttachment ("C:\EBilling_Xtra\logo.png") && ALWAYS DONE SO THAT EVERYBODY HAS THE LOGO
.SEND()
ENDWITH
iMsg = .NULL.
iConf = .NULL.
Flds = .NULL.
ELSE
MESSAGEBOX("Could not send the message, your internet connection is down.")
ENDIF
PROCEDURE displayState
LOCAL lConnected
lConnected = .F.
lpdwFlags = 0
IF InternetGetConnectedState (@lpdwFlags, 0) = 1
lConnected = .T.
ENDIF
RETURN lConnected
ENDPROC


The line:
.HTMLBody = "font size=10 face=verdana>"

is not working. How do I get the font size & style to make it so that the "body" of the email is in that font style and size??


Please let me know.
Thanks,
FOXUP!
 
Hmm. Not really a VFP question. More like something you should ask in an HTML / CSS forum. However, since we are all friends here ....

In broad terms, you need something like this:

[tt].HTMLBody = [<p style="font-family:10; font-family:Arial, Helvetica, Sans-Serif;">Si vous avez besoin d'une autre copie, il est également disponible en ligne<br> ..... etc. etc. </p>][/tt]

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi Mike,

Thank you my friend. :) I appreciate it. :)

That seems to work OK for that one particular line but I concatenate the variable called "bod". is it possible to make that variable's value in that font size & style?


Please let me know.

Thanks,
FOXUP!
 
My point was that you need to wrap the entire text with these two tags.

First, put this tag at the start of the text:
[tt]
<p style="font-family:10; font-family:Arial, Helvetica, Sans-Serif;">[/tt]

and put this one at the end:

[tt]</p>[/tt]

I admit that I didn't bother to read - or try to understand - your entire code. But, having glanced at it more carefully now, I guess you need to do something like this:

Instead of:

[tt].HtmlBody=bod[/tt]

do this:

[tt].HtmlBody = ;
[<p style="font-family:10; font-family:Arial, Helvetica, Sans-Serif;">] + bod +
[</p>][/tt]

Give it a try.

Mike




__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike,

You ROCK !!! As usual, it works & it's perfect. :) Star for you! :)


Thanks again my friend,
FOXUP !

 
The CDO.MESSAGE class HTMLBody property is simply the property, which you set to the full emails HTML text, neither just the html <body>..</body> part nor just the CSS style of it.

You even set HTMLBody in your original code:
Code:
.HtmlBody=bod

So how do you get the idea first setting a font size and font face will set the formatting?
Code:
.HtmlBody="font size=10 face=verdana>"
.HtmlBody=bod

You set the same preoprty twice. To expect that does something is like expecting the following code to show a text in a certain font:
Code:
lcText="WingDings"
lcText="FoxUp"
? lcText

Only some very rare WriteOnly properties (IIRC one such from Crystal Reports, another one I know from serial port classes) allow you to use them like a stack where each assignment adds to a previous assignment. But in the normal case you really just overwrite, what you have written before. So "font size=10 face=verdana>" is simply gone and overwritten with bod.

I'm quite sure you've been told to put a general styling into the html body tag, but that means within the [tt]<body style="...">Mailtext</body>[/tt] of HTML source text, not within the HTMLBody property of a mail object.

They should have named it HTMLText, perhaps, to avoid that double meaning. Well, the world is full of double meanings, often enough reason for good entertainment instead of frustration.

In regard of HTML mail you better put your style into a css section of the html head section of a full html page and not start with an IMG tag. Normally CSS even best goes into a separate file, but that's just complicating things for mails, where you ideally have everything inside the one html code you set as mail body.

Ah, just by saying/writing that - the latter also probably is the source of the HTMLBody property name, as there also is the TextBody for text only mails. So body here refers to the mail body, not the html body. It means the mail body being HTML, not the <body> of the html. To be clear: CDO.MESSAGE does not add all other HTML parts for you, it's just mail clients do like browsers gracefully also render partly HTML as html page. Ideally you set this to a full html page.ü

To not just say, what has become unimportant for this solved case, you best prepare your mail text with TEXT..ENDTEXT the following way, and this includes a full HTML5 skeleton:
Code:
LOCAL lcHTMLBody
TEXT TO lcHTMLBody TEXTMERGE NOSHOW
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="ISO-8859-1">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Mail subject</title>
</head>
<body style="font-family:Calibri, Helvetica, Arial, Sans-Serif; background-color:lightgrey; font-size:10pt;">
[COLOR=#00D200]<p>Dear Sir,</p>
<p>Today is <<Date()>>, only one week until <<Date()+7>>.</p>[/color]
</body>
</html>
ENDTEXT
The green part is where you can do what you like. The other part isn't taboo to change, but first know what you're doing. I intentionally chose charset="ISO-8859-1" because that rather corresponds to some of the normally used ANSI codepages VFP uses and VFP is capable to put into the HTML string, though UTF-8 is HTML standard. You might also change that, as CDO.MESSAGE is a COM/OLE class and would get the text set via automatic codepage translations you can influence via SYS(3101), so you can let that turn the ANSI VFP text to UTF-8.

Aside of that, HTML5 is much cleaner, for example HTML4 doctypes would not simply be <!DOCTYPE html> but [tt]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "[/tt] - something just contributing to how a browser should interpret the code, not visible to the reader. It has become much more friendly to do HTML.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top