Solved Using a Rich Text textbox for the HTML body of an email.

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 18:55
Joined
Sep 12, 2006
Messages
15,955
I thought I was going off topic with @isladogs thread about the Access conference, so I have added a new one.

What I was trying to do was using an Access rich text textbox to become the HTML body of an email.

So a function that produces plaintext from a formatted text box, doesn't really help. What you really need is a way to change the rich text codes into HTML, assuming you can do it as a simple replace operation. It sounds like handling tag pairs in this way is something that a JSON expert could knock up !

I'm sure I saw a MS note saying rich text WAS HTML, but I don't think that's true, is it? Maybe it is, and the trick is to handle the body text in an email message correctly. Maybe there's a technique to correctly using either the .body or .htmlbody property of a mail object correctly. I can't find any help though.

So, can you design a rich text box with colours and formatting, text only, no images, and use the rich text box coding directly to produce a similar formatted email. Maybe it's easy, and I'm just missing the point.

Can anyone help?
 
I'm sure I saw a MS note saying rich text WAS HTML, but I don't think that's true, is it?
What version of Acces are you using, Dave?

Access chaged its RichText from old style tags to a subset of HTML some time after Acc2K7.
 
I toyed around with this for word, and couldn't make it work, although I did discover that you can cut and paste it and it works:

1699362459192.png


So could you put the text into the clipboard and then paste it in the Email?
The stored text is
Code:
<div><strong>Testing <font color=red>RED </font><font color="#2F5496">BLUE <em>italic </em></font><font
color="#538135"><em>Green </em></font></strong><font color=black>normal</font></div>
 
I'm using A365 for this, so it's the latest version. Thanks for the note about the current format @cheekybuddha

So at the moment I am doing something like

mymail.body = emailtext
mymail.send
(actually mymail.save for testing)

I'll try mymail.HTMLbody, and see if that makes a difference.

Maybe I need to set the email format to comply somehow.

I have to go out now, but I will have another play around later, now you have given me some ideas.

( can't cut and paste as I have a large number of emails to send, and I am iterating a collection of personal details, each email address getting a personalised version of the same email )
 
Last edited:
Code:
mymail.body = PlainText(emailtext)
mymail.HTMLbody = emailtext   ' rich text from Access
mymail.send
 
Code:
mymail.body = PlainText(emailtext)
mymail.HTMLbody = emailtext   ' rich text from Access
mymail.send

Got it!

So do I populate either mymail.HTMLBody or mymail.Body but not both, and then outlook will use whichever is in the record?

I have this code effectively ..

Code:
If Len(HTMLString > 0 Then
            MyMail.HTMLBody = HTMLString
        Else
            MyMail.body = NormalString
        End If
 
Dave
Thanks for starting a separate thread. I agree it was hijacking the original!

Anyway, my example CDO email app includes HTML which may be of use
Like @Minty, I would suggest using a table for the rich text (a subclass of HTML)

 
I've got it working, but

I had incorporated a merge code in my text {recipient} and I try to replace {recipient} with the recipient name, eg "Mr Smith" within the HTML and as soon as I do that, I no longer get an HTML formatting, just a plain text email.

I even tried to make sure I replace {recipient } 40 characters long, with a string of exactly the same length, but that replace process seems to break the HTML somehow. I first tried padding the {recipient} with a standard number of space characters, but it automatically deleted all the trailing spaces. I then tried a string of periods. It reproduced the correct number of periods, but it still dropped all of the formatting. So at the moment I only seem to be able to get a plaintext email.
 
Perhaps paste the 'pre' and 'post' html here so we can try and identify what's wrong.

At what stage in your code do you perform the Replace() ?
 
Here you go

EMailTemplate shows my email design
EmailBody is plain text
EmailBody is HTML, with a larger font bold header, and a yellow recipient.

Recipient shoes the name David Bloggs, which will actually get shown as Mr Bloggs.

EMail_HTML(1)
So, if I generate the email without trying to replace the text, I get the email formatted correctly.

EMail_HTML(1)
if I replace the recipient with the recipient name the text, I get plain text, but it still has the Re Your Order line to demonstrate that it's using the HTML version

I am using a replace code to replace {recipient} with "Mr Bloggs". Actually I am doing this within the outlook email HTMLbody. I will try doing it with the HTML text before I assign it to the email, and see if that makes a difference.
 

Attachments

  • Email_HTML(1).PNG
    Email_HTML(1).PNG
    9.5 KB · Views: 115
  • Email_HTML(2).PNG
    Email_HTML(2).PNG
    8.6 KB · Views: 112
  • EMailTemplate.PNG
    EMailTemplate.PNG
    10.1 KB · Views: 110
  • recipient.PNG
    recipient.PNG
    1.5 KB · Views: 107
Last edited:
SUCCESS

I tried that last idea. I massaged the email text before assigning it the the outlook object, and that seemed to work. I just need to test multiple emails now, to make sure they get processed correctly. Yes, all working OK now.

I have marked this solved.
 
Last edited:
Yes, I would imagine that you would want something like:
Code:
emailtext = Replace(emailtext, "{Recipient}", Me.txtTitle & " " & Me.txtSurname)
mymail.body = PlainText(emailtext)
mymail.HTMLbody = emailtext   ' rich text from Access
mymail.send

But you've got there, so whatever you did was the answer! (y) (y)
 
Yes, that's what I was trying to do, but I was assigning the .HTMLbody first and then trying to replace the text in the .HTMLbody, which was the problem.
 

Users who are viewing this thread

Back
Top Bottom