New line code issue

mafhobb

Registered User.
Local time
Today, 00:20
Joined
Feb 28, 2006
Messages
1,249
Hi

I have some code to send e-mails (smtp) out in my db that works really well, however I am having an issue with the text I send.

Specifically I use vbCrLf in the code to move to a new line in my e-mail body. This works well on my screen preview and also on my Groupwise email client if I have the mail settings adjusted to view HTML, however, when I view the same message on gmail, for example, all the text is in one piece...no new lines...it is all garbled up together.

How can I fix this?

Thanks

mafhobb
 
Hi

I have some code to send e-mails (smtp) out in my db that works really well, however I am having an issue with the text I send.

Specifically I use vbCrLf in the code to move to a new line in my e-mail body. This works well on my screen preview and also on my Groupwise email client if I have the mail settings adjusted to view HTML, however, when I view the same message on gmail, for example, all the text is in one piece...no new lines...it is all garbled up together.

How can I fix this?

Thanks

mafhobb

Hi

can you post your code where your error is? its very hard to second guess

thanks
 
As Nigel has suggested, post your code for us to see.. On a stab in the dark.. Set the format of the email as HTMLBody..
 
Here is my code for sending the e-mail

Code:
Public Function SendsmtpEmailwAttachement(txtRecipient As String, txtSender As String, txtsubject As String, txtbody As String, stratt As String) As String

Dim mail

Set mail = Nothing

' Send by connecting to port 25 of the SMTP server.
Dim iMsg
Dim iConf
Const cdoSendUsingPort = 2
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields

'   Set the CDOSYS configuration fields to use port 25 on the SMTP server.

With Flds
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "xx.x.xx.xx"
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
    .Update
End With

' Apply the settings to the message.
With iMsg
    Set .Configuration = iConf
    .to = txtRecipient
    .From = txtSender
    .Subject = txtsubject
    .HTMLBody = txtbody
    .AddAttachment stratt
DoEvents
    .Send
End With

' Clean up variables.
Set iMsg = Nothing
Set iConf = Nothing

End Function

This is an example of what I use to create e-mail body:
Code:
Me.txtBod = " Sehr geehrter Kunde, wir haben den Artikel von ihnen Repariert. Im Anhang der E-Mail befindet sich die Rechnung für die Reparatur." & vbCrLf & vbCrLf & " Vielen Dank." & vbCrLf & vbCrLf & "Ihr xxxx Service Team."

The e-mail sends fine.

When viewed in Groupwise using plain text settings it looks like this:
Code:
Sehr geehrter Kunde, wir haben den Artikel von ihnen Repariert. Im Anhang der E-Mail befindet sich die Rechnung für die Reparatur. Vielen Dank. Ihr Revell Service Team.

When viewed in Groupwise using HTML setting it looks like this:
Code:
Sehr geehrter Kunde, wir haben den Artikel von ihnen Repariert. Im Anhang der E-Mail befindet sich die Rechnung für die Reparatur.

Vielen Dank.

Ihr Revell Service Team.

When viewed in Gmail, regardless of the viewing settings it looks like this:
Code:
Sehr geehrter Kunde, wir haben den Artikel von ihnen Repariert. Im Anhang der E-Mail befindet sich die Rechnung für die Reparatur. Vielen Dank. Ihr Revell Service Team.

How can I ensure that the new line code is always respected regardless of the e-mail client? I realize that may not happen in all cases, but how about most? Is vBcrLf not being recognized by gmail?

mafhobb
 
Since you are using HTMLBody, try <br> instead of vbCrLf..
Code:
Me.txtBod = " Sehr geehrter Kunde, wir haben den Artikel von ihnen Repariert. " & _
            "Im Anhang der E-Mail befindet sich die Rechnung für die Reparatur.<br><br>" & _
            "Vielen Dank.<br><br>Ihr xxxx Service Team."
 
Since you are using HTMLBody, try <br> instead of vbCrLf..
Code:
Me.txtBod = " Sehr geehrter Kunde, wir haben den Artikel von ihnen Repariert. " & _
            "Im Anhang der E-Mail befindet sich die Rechnung für die Reparatur.<br><br>" & _
            "Vielen Dank.<br><br>Ihr xxxx Service Team."

Yes, I think I need to do that, however, the problem is that if I use <br> instead of vbcrlf to build the body, then the e-mail preview in Access (a textbox with the body to edit it if necessary) does not display correctly as it does not recognize <br>.

Perhaps I need to replace vbcrlf with <br> after the text has been reviewed and right before sending it? Do you think that would solve the issue?

If so, is there any automatic "find and replace" code that you know of to do this?

mafhobb
 
You have the answer.. :)

Just keep the code as such in the Me.txtBod, i.e. with the vbCrLf... and in the HTMLBody.. use..
Code:
.HTMLBody = Replace(txtBody, vbCrLf, "<br>")
 
That worked for the vbcrlf, but how can I get rid of the "&"? I get an error when writing txtbody = Replace(txtbody, & , " ") in the code as after "&" it expects an expression

mafhobb
 
Putting the & between quotations worked!

Thanks everybody

Thanks pr2-eugin!

mafhobb
 
Glad you have it sorted.. :)

Just a quick note, you do not need to Replace the & character.. It is just the concatenation operator.. Code in Post#7 is more that enough to get what you want..
 

Users who are viewing this thread

Back
Top Bottom