Link to home
Create AccountLog in
Avatar of access_dude
access_dude

asked on

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("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2                   ' Use this mode in conjunction with the next line.
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = GetServerNameSMTP()
        .Update
    End With
   
    With iMsg
        Set .Configuration = iConf
        .To = "YourEmail@hotmail.com"               ' DON"T FORGET TO CHANGE HERE
        .cc = ""
        .bcc = ""
        .FROM = "YouEmail@hotmail.com"             ' DON"T FORGET TO CHANGE HERE
        .Subject = "Subject"
        .TextBody = "Body"
        .AddAttachment "C:\TESTFILE.TXT"
        .send
    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)

Line1[]Line2

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

ASKER CERTIFIED SOLUTION
Avatar of Computron
Computron

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of access_dude
access_dude

ASKER

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?