CDO keeps reformatting file

The following code creates a file called "TESTFILE.TXT" and emails to a recipient.  Don't forget to change .TO and .FROM

Public Sub TEST()
    Open "C:\TESTFILE.TXT" For Output As #1    ' Open file for output.
    Print #1, "Line 1"    ' Print text to file.
    Print #1, "Line 2"
    Close #1

    Dim iMsg As Object
    Dim iConf As Object
    Set iMsg = CreateObject("CDO.Message")
    Set iConf = CreateObject("CDO.Configuration")
    With iConf.Fields
        .Item("") = 2                   ' Use this mode in conjunction with the next line.
        .Item("") = GetServerNameSMTP()
    End With
    With iMsg
        Set .Configuration = iConf
        .To = ""               ' DON"T FORGET TO CHANGE HERE
        .cc = ""
        .bcc = ""
        .FROM = ""             ' DON"T FORGET TO CHANGE HERE
        .Subject = "Subject"
        .TextBody = "Body"
        .AddAttachment "C:\TESTFILE.TXT"
    End With
End Sub

If I send the file using mouse and keyboard it works fine on the receipt of attachment.  When I use the code above to send, the attachment goes through with screwed up CRLF's  i see a square when open the received attachment in notepad.

Expected contents on received file

Line 1
Line 2

Observed contents on received file (the [] is one square character probably a ascii 10 or a ascii13 only instead of both)


QUESTION: How do i get CDO to NOT screw up the CRLF's?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Try this instead

    Print #1, "Line 1" & vbCRLF & "Line 2"

In other words, you're using Print only once.

Internet e-mail standards forbid the presence of bare linefeed characters in e-mail messages. If you are sure to use carriage return before linefeed, this may take care of this issue. I believe something is happening in the creation but this would be a good way to test it.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's not CDO that is screwing it up.....its your Print to file commands

You might get more control using MS scripting runtime library

Dim objFSO As New FileSystemObject
Dim objTS As TextStream

Set objTS = objFSO.OpenTextFile("C:\TESTFILE.TXT", ForAppending, True)
objTS.WriteLine "Line1"
objTS.WriteLine "Line2"
Set objTS = Nothing
Set objFSO = Nothing
access_dudeAuthor Commented:
Tried this in our office and both methods worked fine.  I wonder if this may have something to do with their SMTP email server?  They are not using exchange.  I'm going to need a few days (or weeks) to check this out on the clients.  If the scriping library approach works at the client's then the points are yours.
as per Access_dudes last comment "Tried this in our office and both methods worked fine."

So it appears we both gave correct answers, however I don't know whether or not he got to try out the MS Scripting library approach?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.