objEmail.HTMLBody inserts "! " after 1900 characters?

L

Leo Mansi

I have code in a module that is sending e-mails, the content of which varies
beased upon the content of fields within the database. I am creating the
body using a number of string variables and then concatenating them together
and assigning them to the objEmail.HTMLBody object similar to this:

CompleteBody = Body1 & Body2 & Body3 & Body4
objEmail.HTMLBody = CompleteBody

Originally, I wasn't using so many variables, but have modifed the code to
try to resolve my problem.

When the e-mail is sent, an exclamation point and a space are inserted in
about the 1907th position. The record I have been testing with, generates
2308 characters in CompleteBody. I get all of the characters, but get the
"! " inserted in the same position each time.

I have changed the line assigning Complete Body to objEmail.HTMLBody to
read:

objEmail.HTMLBody = "12345" & CompleteBody

Then the location of the "! " comes 5 characters sooner in the text, still
in the 1907th position.

I am baffled. If I were exceeding limitations, I would be losing characters
at the end of my e-mail. But I am not. I get all of the text, but have the
"! " inserted.

Any guidance you can provide will be greatly appreciated.

Leo Mansi
(e-mail address removed)
 
J

Joshua A. Booker

Leo,

This doesn't happen for me. Does it for you using this code?

Function TestEmail(Optional AttachmentPath)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim stBody as String

Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

With objOutlookMsg
For i = 1 To 2308
stBody = stBody & "A"
Next i
.HTMLBody = stBody
.Display
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing

End Function

If not, are you sure the "! " is not in your CompleteBody? Try this:

Debug.Print Instr(1900,CompleteBody,"! ")

If anything other than zero is returned to the debug window than it's in
there.

HTH,
Josh
 
L

Leo Mansi

Josh,

First off, thanks for taking the time to respond to my post.

I tried both of the things you suggested. When I ran the function, I got
the 2308 A's with not stray characters. When I did the debug, the result was
0. I had done similar within my code a few days ago using INSTR to search
for "! " and it had returned 0.

Then I let the code send the e-mail and here is the paragraph where I am
having the problem:

If this address is incorrect or changes, please let us know. Otherwise we
will no! t be able to keep you up to date regarding upgrades and other
information about the software.

I then changed my code to read:
objEmail.HTMLBody = "12345" & CompleteBody

This is the result I got in the e-mail:

If this address is incorrect or changes, please let us know. Otherwise we
wi! ll not be able to keep you up to date regarding upgrades and other inf
ormation about the software.

I then searched my procedure for "! " and it wasn't found. I also searched
for chr and only found references to chr(34) to insert quotes.

Any other ideas?

Thanks again,

Leo
 
J

Joshua A. Booker

Leo,

Flukey!
Does it happen on other records besides your test record?
Have you tried setting the .Body property instead of .HTMLBody?
Try right clicking on the email body in Outlook and choose View Source to
see if you get any clues.

Josh
 
L

Leo Mansi

Josh,

Thanks for sticking with me! It certainly is flukey!!! And driving me crazy!

I have tried to eliminate all the variables I can to figure this out. Below
is code that still produces the error on my end, but is not linked to any
fields in my database. Substitue an e-mail address in the 2 places where is
says "Put e-mail address here" and try it out.

Sub SendActivationEMail()

Dim strContactEmail, strEmailFrom As String
Dim Body1, Body2, Body3, Body4, Body5, Body6, Body7, Body8, Body9,
Body10, Body11, Body12, Body13, Body14, Body15, Body16, Body17, CompleteBody
As String

strEmailFrom = "Put e-mail address here"
strContactEmail = "Put e-mail address here"

Set objEmail = CreateObject("CDO.Message")
objEmail.From = strEmailFrom
objEmail.To = strContactEmail
objEmail.Subject = "RxAssist Plus WebFast Activation for " &
"strClinicName"

Body1 = "1234567890 1234567890 1234567890 1234567890 1234567890
1234567890 1234567890 1234567890 "
Body2 = "1234567890 1234567890 1234567890 1234567890 1234567890
1234567890 1234567890 1234567890 "
Body3 = "1234567890 1234567890 1234567890 1234567890 1234567890
1234567890 1234567890 1234567890 "
Body4 = "1234567890 1234567890 1234567890 1234567890 1234567890
1234567890 1234567890 1234567890 "
Body5 = "1234567890 1234567890 1234567890 1234567890 1234567890
1234567890 1234567890 1234567890 "
Body6 = "1234567890 1234567890 1234567890 1234567890 1234567890
1234567890 1234567890 1234567890 "
Body7 = "1234567890 1234567890 1234567890 1234567890 1234567890
1234567890 1234567890 1234567890 "
Body8 = "1234567890 1234567890 1234567890 1234567890 1234567890
1234567890 1234567890 1234567890 "
Body9 = "1234567890 1234567890 1234567890 1234567890 1234567890
1234567890 1234567890 1234567890 "
Body10 = "1234567890 1234567890 1234567890 1234567890 1234567890
1234567890 1234567890 1234567890 "
Body11 = "1234567890 1234567890 1234567890 1234567890 1234567890
1234567890 1234567890 1234567890 "
Body12 = "1234567890 1234567890 1234567890 1234567890 1234567890
1234567890 1234567890 1234567890 "
Body13 = "1234567890 1234567890 1234567890 1234567890 1234567890
1234567890 1234567890 1234567890 "
Body14 = "1234567890 1234567890 1234567890 1234567890 1234567890
1234567890 1234567890 1234567890 "
Body15 = "1234567890 1234567890 1234567890 1234567890 1234567890
1234567890 1234567890 1234567890 "
Body16 = "1234567890 1234567890 1234567890 1234567890 1234567890
1234567890 1234567890 1234567890 "

CompleteBody = Body1 & Body2 & Body3 & Body4 & Body5 & Body6 & Body7 &
Body8 & Body9 & Body10 & Body11 & Body12 & Body13 & Body14 & Body15 & Body16

objEmail.HTMLBody = CompleteBody
'objEmail.HTMLBody = "12345" & CompleteBody

objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
"smtp.conversent.net"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send

MsgBox "Activation letter sent and activity recorded."


End Sub

Thanks again!

Leo
 
J

Joshua A. Booker

Leo,

Sorry to say, it came through clean on my end. I even tried it after
doubling the number of characters and it worked. Are you saying it happens
with fewer than 1900 chr now? Your code has 1400+ so I doubled it.

I looked online for known isues and found nothing but I was focused on
Outlook automation not CDO.

Best of Luck,
Josh
 
L

Leo Mansi

Josh,

I didn't even check the number of characters because it happened in the
e-mail created by that code. Here is the result I got:

1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890
1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890
1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890
1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890
1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890
1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890
1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890
1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890
1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890
1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890
1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890
1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890
1234567890 1234567890 1234567890 1234567890 1234567890 1234567890! 1234567890
1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890
1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890
1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890
1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890
1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890
1234567890 1234567890

And it doesn't only occur when the code is run on one machine. Several
mchines produce the same result.

Thanks for your assistance! I'm going to keep searching.
 
L

Leo Mansi

Josh,

You had already guided me down that road. In the first message you sent,
the example with all the A's had used the Outlook obj. So this morning, I
googled that and found code to help me convert what I was doing to use the
Outlook object. So far, that seemed to solve my problem! Now I am seeking
away to set the From address... Outlook generally uses the default mailbox.
I want it to use a specific from address because multiple people will be
processing these applications. I have found one article that says you can't
do it. Then found another that says you can, but the code in that one didn't
work for me. So I continue searching.

Thanks for all your help!

Leo Mansi
 
R

Robert Morley

It's been a while since I set up code to send as someone else, but try the
"SendOnBehalfOf" propertly...at least I think that's it. My work laptop is
turned off right now, if you don't get anywhere with that, send me a message
tomorrow, and I'll have a closer look at what it is I'm doing on the laptop.
I might've just set up multiple mailboxes in Outlook, and am doing something
funky...honestly don't remember the specifics, but as I said, I'll try to
look tomorrow if you need.



Rob
 
L

Leo Mansi

Thanks, Rob.

The property is actually "SentOnBehalfOfName". I am using that. I don't
really like it in that it shows the e-mail coming from another address on
behalf of the address I would like it to show, but if the recipient clicks on
Relpy, it does put in the correct address. And with all the unexpected time
I've spent on this because of the other glitch, I'm accepting things the way
they are right now.

Thanks for your assistance.

Leo
 
M

mcescher

Sorry to join so late.
I've used the vbsendmail.dll, and it's quite useful. Google for it.

It doesn't even require Outlook to be open at the time.
Also doesn't give you that "wait for five seconds" message that Outlook
does.

HTH,
Chris M
chris not meinders at gmail not com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top