Solved

Line breaks in email

Posted on 2012-03-20
15
379 Views
Last Modified: 2012-03-26
I have some code that sends out an email in Access 2003.

"Line1" & vbCrLf & _
"Line2" & vbCrLf & _
vbCrLf & vbCrLf & vbCrLf & _
            "We respect your privacy. " &  vbCrLf

That is then put with some other text.  It works and the output in the email is neatly formatted as:

Line1
Line2


West respect your privacy.


However when that email is replied to that same text is reformatted as:

Line1 Line2


West respect your privacy.


Is it possible to prevent this and keep my line breaks in a replied email?  (Using Outlook 2003)  I'm thinking that Outlook is removing extra spaces?
0
Comment
Question by:thandel
  • 4
  • 3
  • 3
  • +3
15 Comments
 
LVL 33

Expert Comment

by:Norie
ID: 37745499
It could be Outlook, or whatever the mail client is,  on the receiving side that's losing th formatting.

I know that's happened to me in the past, you send a nicely formatted message and it comes back as part of the reply in a bit of a jumble.
0
 

Author Comment

by:thandel
ID: 37745502
Exactly.... the rest is holding just these few lines loosing the return... hoping to find a resolve.
0
 
LVL 27

Expert Comment

by:tliotta
ID: 37745546
You show some basic code that apparently generates e-mail. Can you show the actual generated text? The generated text will be where any solution becomes apparent, if at all.

Tom
0
 

Author Comment

by:thandel
ID: 37745551
The generated text was pasted into the question.
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 37745885
If the recipient replies in HTML format, the line breaks in your plain text format are ignored.  Line breaks in HTML require the <br> tag, not vbCrLf or cr/lf or \r\n.  I'm sure Outlook is doing some reformatting also.
0
 
LVL 26

Expert Comment

by:Nick67
ID: 37748082
To troubleshoot, you could have your code format up the email message as HTML and see what happens

Instead of .Body = "some strings"

you'd have

.BodyFormat = olFormatHTML
.HTMLBody = "Line1" & "<br>"
.HTMLBody =.HTMLBody & "Line2" & "<br>"
.HTMLBody =.HTMLBody & "<br><br><br>We respect your privacy.<br>"


If Outlook is the formatting villain, this may get you around it
(When I do code like this I use an Outlook reference, and can therfore use the constant olFormatHTML.  I am not sure what number it represents, if you are using late-binding)
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37748247
I'm with imnorie...

I have Outlook (set to send/read in HTML) and the reply looks fine.
(Line breaks look the same as in the reply as in the original email)

This may be an issue with the recipients email settings.

In which case there may not be that much you can do, ..short of *forcing* them to change their settings...


...You can go all out and create the email via Automation (then try using .HTMLBody and using  <br> instead of vbcrlf...) but even this may not work, and seems like overkill...

JeffCoachman
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 27

Expert Comment

by:tliotta
ID: 37749141
The generated text was pasted into the question.

What you pasted does not look like valid SMTP text. But if those are indeed the actual characters in the SMTP text (which seems unlikely), then what characters are you using for carriage-return (CR) and line-feed (LF)? CR should be 7-bit ASCII code 13, and LF should be 7-bit ASCII code 10.

Note that the physical text of a SMTP e-mail is not HTML nor RTF nor anything other than quoted-printable 7-bit ASCII. So, the actual text portion is needed rather than any HTML or RTF or other embedded attachment such as is created for HTML mail for example.

Tom
0
 
LVL 33

Expert Comment

by:Norie
ID: 37749460
Tom

vbCrLf is Chr(13) & Char(10).

If you try Len(vbCrLf) in VBA it returns 2.
0
 
LVL 27

Expert Comment

by:tliotta
ID: 37754998
If you try Len(vbCrLf) in VBA it returns 2.

True, but that is not what the actual text of the e-mail will be. The definition of the issue will involve the physical text of an e-mail item, not any program/script statements that create an e-mail.

In order to have an idea about what some (possibly unknown) e-mail client is going to do with an item, it is necessary to know what is actually received by clients. From there, it can be worked backwards to code that generates and to probable changes that will generate more predictable e-mail.

If an e-mail item is saved as a file and then opened with, e.g., Notepad, the actual item will be seen. That's what should illuminate probable causes of strange or undesired behaviors.

Tom
0
 
LVL 26

Expert Comment

by:Nick67
ID: 37755046
My underlying assumption from the code the OP posted is that VBA is being used in Access to automate Outlook.  Another possibility is DoCmd.SendObject.  Either one of these methods only takes strings for inputs to the message body.  If you are automating Outlook, you can specify that you'd like HTML output and feed in an appropriately formatted bit of HTML  as a string.

But I don't think that there is much else that VBA/Access can do with either of these two methods to muck with formatting.  The vagarities of the receiving client cannot likely be overcome.
0
 

Author Comment

by:thandel
ID: 37755550
Well in order to send this emails without minimun Outlook security alerts and to keep code simple I used.

DoCmd.SendObject , , , Me.Email, , , sSubject, sBody

As far as I can tell I can not use any sort of HTML code with SendOjbect.  I think the sort answer to my question is its not possible.
0
 
LVL 26

Expert Comment

by:Nick67
ID: 37757880
I'd have to agree.
SendObject is pretty rudimentary.

Automating Outlook does have some benefits as well as the one security prompt drawback.
For one, the resulting email winds up in Sent Items which can be nice for traceablity.

But now, from the Access 2003 help


The SendObject method carries out the SendObject action in Visual Basic.

expression.SendObject(ObjectType, ObjectName, OutputFormat, To, Cc, Bcc, Subject, MessageText, EditMessage, TemplateFile)
expression    Required. An expression that returns one of the objects in the Applies To list.

ObjectType   Optional AcSendObjectType.

AcSendObjectType can be one of these AcSendObjectType constants.
acSendDataAccessPage
acSendForm
acSendModule
acSendNoObject default
acSendQuery
acSendReport
acSendTable

ObjectName   Optional Variant. A string expression that's the valid name of an object of the type selected by the objecttype    argument. If you want to include the active object in the mail message, specify the object's type with the objecttype    argument and leave this argument blank. If you leave both the objecttype    and objectname    arguments blank (the default constant, acSendNoObject, is assumed for the objecttype    argument), Microsoft Access sends a message to the electronic mail application without an included database object. If you run Visual Basic code containing the SendObject method in a library database, Microsoft Access looks for the object with this name first in the library database, then in the current database.

OutputFormat   Optional Variant.

To   Optional Variant. A string expression that lists the recipients whose names you want to put on the To line in the mail message. Separate the recipient names you specify in this argument and in the cc    and bcc    arguments with a semicolon (;) or with the list separator set on the Number tab of the Regional Settings Properties dialog box in Windows Control Panel. If the recipient names aren't recognized by the mail application, the message isn't sent and an error occurs. If you leave this argument blank, Microsoft Access prompts you for the recipients.

Cc   Optional Variant. A string expression that lists the recipients whose names you want to put on the Cc line in the mail message. If you leave this argument blank, the Cc line in the mail message is blank.

Bcc   Optional Variant. A string expression that lists the recipients whose names you want to put on the Bcc line in the mail message. If you leave this argument blank, the Bcc line in the mail message is blank.

Subject   Optional Variant. A string expression containing the text you want to put on the Subject line in the mail message. If you leave this argument blank, the Subject line in the mail message is blank.

MessageText   Optional Variant. A string expression containing the text you want to include in the body of the mail message, after the object. If you leave this argument blank, the object is all that's included in the body of the mail message.

EditMessage   Optional Variant. Use True (–1) to open the electronic mail application immediately with the message loaded, so the message can be edited. Use False (0) to send the message without editing it. If you leave this argument blank, the default (True) is assumed.

TemplateFile  Optional Variant. A string expression that's the full name, including the path, of the file you want to use as a template for an HTML file.

EditMessage and TemplateFile would seem to imply that you can use HTML, and that you can have the message open before actually sending it.
If you do so, what does it look like?
0
 

Author Comment

by:thandel
ID: 37764143
If I preview before sending the format is fine.  So the odd part is that if I don't send it and then click on reply (from the outbox) then the wrap issue returns... but looking at the email in the outbook the wrap is fine????? So its like Outlook is loosing the format after its sending or when using the same email in a reply.
0
 
LVL 82

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 37764370
I think almost all email clients reformat the content to some degree when you reply or forward.  If you do something as simple as going from plain text to HTML format, things will change because the line break methods are different.  I think what you are wanting is impossible to guarantee.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now