ASP CDOSYS SMTP Email attachments are being corrupted

Discussion in 'ASP General' started by rschaeferhig, Mar 27, 2006.

  1. rschaeferhig

    rschaeferhig Guest

    I have an ASP page that uses CDOSYS to send a simple HTML format email with a
    PDF attachment. When I open the PDF attached to the email it shows up as a
    blank page. I log into the web server console and open the same PDF in the
    source directory and it opens fine. I run a binary comparison of the source
    and attached files and there's a difference: one byte, x'2E' is missing at
    offset x'0231'. If I save the attached file and use a hex editor to insert
    the x'2E' the file opens just like the original.

    Any ideas? I'm baffled...
     
    rschaeferhig, Mar 27, 2006
    #1
    1. Advertising

  2. "rschaeferhig" <> wrote in message
    news:...
    > I have an ASP page that uses CDOSYS to send a simple HTML format email

    with a
    > PDF attachment. When I open the PDF attached to the email it shows up as a
    > blank page. I log into the web server console and open the same PDF in the
    > source directory and it opens fine. I run a binary comparison of the

    source
    > and attached files and there's a difference: one byte, x'2E' is missing at
    > offset x'0231'. If I save the attached file and use a hex editor to insert
    > the x'2E' the file opens just like the original.
    >
    > Any ideas? I'm baffled...


    Windows 2003 server right?

    I've come across this at a few of my client's sites but I haven't found out
    why it happens. I seems that CDOSYS ends up using binary encoding rather
    than Base64 encoding when creating the attachment body part. It doesn't
    happen all system though.

    In the end I just used the following code to create the attachment myself:-


    Function AddAttachment(Message, Source, FileName, MimeType)

    Dim oPart ' As IBodyPart
    Dim oStreamIn ' As ADODB.Stream
    Dim oStreamOut ' As ADODB.Stream

    Set oPart = Message.Attachments.Add

    oPart.ContentMediaType = MimeType & "; Name = """ & FileName & """"
    oPart.ContentTransferEncoding = "base64"
    oPart.Fields("urn:schemas:mailheader:content-disposition").Value =
    "attachment; FileName = """ & FileName & """"
    oPart.Fields.Update

    Set oStreamIn = Server.CreateObject("ADODB.Stream")

    oStreamIn.Open
    oStreamIn.Type = adTypeBinary
    oStreamIn.LoadFromFile Source

    Set oStreamOut = oPart.GetDecodedContentStream

    oStreamIn.CopyTo oStreamOut

    oStreamOut.Flush

    oStreamIn.Close

    Set AddAttachment = oPart

    End Function


    Given a MyStuff.PDF in the folder C:\temp this function is called as:-



    Dim oMsg

    Set oMsg = Server.CreateObject("CDO.Message")

    'Set From, To, etc.
    oMsg.TextBody = "Blah Blah"

    AddAttachment oMsg, "c:\temp\MyStuff.pdf", "MyStuff.pdf", "application/pdf"

    oMsg.Send



    HTH

    Anthony.
     
    Anthony Jones, Mar 27, 2006
    #2
    1. Advertising

  3. rschaeferhig

    rschaeferhig Guest

    "Anthony Jones" wrote:

    >
    > "rschaeferhig" <> wrote in message
    > news:...
    > > I have an ASP page that uses CDOSYS to send a simple HTML format email

    > with a
    > > PDF attachment. When I open the PDF attached to the email it shows up as a
    > > blank page. I log into the web server console and open the same PDF in the
    > > source directory and it opens fine. I run a binary comparison of the

    > source
    > > and attached files and there's a difference: one byte, x'2E' is missing at
    > > offset x'0231'. If I save the attached file and use a hex editor to insert
    > > the x'2E' the file opens just like the original.
    > >
    > > Any ideas? I'm baffled...

    >
    > Windows 2003 server right?
    >
    > I've come across this at a few of my client's sites but I haven't found out
    > why it happens. I seems that CDOSYS ends up using binary encoding rather
    > than Base64 encoding when creating the attachment body part. It doesn't
    > happen all system though.
    >
    > In the end I just used the following code to create the attachment myself:-
    >
    >
    > Function AddAttachment(Message, Source, FileName, MimeType)
    >
    > Dim oPart ' As IBodyPart
    > Dim oStreamIn ' As ADODB.Stream
    > Dim oStreamOut ' As ADODB.Stream
    >
    > Set oPart = Message.Attachments.Add
    >
    > oPart.ContentMediaType = MimeType & "; Name = """ & FileName & """"
    > oPart.ContentTransferEncoding = "base64"
    > oPart.Fields("urn:schemas:mailheader:content-disposition").Value =
    > "attachment; FileName = """ & FileName & """"
    > oPart.Fields.Update
    >
    > Set oStreamIn = Server.CreateObject("ADODB.Stream")
    >
    > oStreamIn.Open
    > oStreamIn.Type = adTypeBinary
    > oStreamIn.LoadFromFile Source
    >
    > Set oStreamOut = oPart.GetDecodedContentStream
    >
    > oStreamIn.CopyTo oStreamOut
    >
    > oStreamOut.Flush
    >
    > oStreamIn.Close
    >
    > Set AddAttachment = oPart
    >
    > End Function
    >
    >
    > Given a MyStuff.PDF in the folder C:\temp this function is called as:-
    >
    >
    >
    > Dim oMsg
    >
    > Set oMsg = Server.CreateObject("CDO.Message")
    >
    > 'Set From, To, etc.
    > oMsg.TextBody = "Blah Blah"
    >
    > AddAttachment oMsg, "c:\temp\MyStuff.pdf", "MyStuff.pdf", "application/pdf"
    >
    > oMsg.Send
    >
    >
    >
    > HTH
    >
    > Anthony.
    >
    >
    >
     
    rschaeferhig, Mar 28, 2006
    #3
  4. rschaeferhig

    rschaeferhig Guest

    Oops.

    Windows 2000 Server AND Windows 2003 Server, but I'll give it a shot. I
    suspected an encoding problem, I've just never had any experience doing my
    own encoding so I had no idea where to start.

    thanks.

    "Anthony Jones" wrote:

    >
    > "rschaeferhig" <> wrote in message
    > news:...
    > > I have an ASP page that uses CDOSYS to send a simple HTML format email

    > with a
    > > PDF attachment. When I open the PDF attached to the email it shows up as a
    > > blank page. I log into the web server console and open the same PDF in the
    > > source directory and it opens fine. I run a binary comparison of the

    > source
    > > and attached files and there's a difference: one byte, x'2E' is missing at
    > > offset x'0231'. If I save the attached file and use a hex editor to insert
    > > the x'2E' the file opens just like the original.
    > >
    > > Any ideas? I'm baffled...

    >
    > Windows 2003 server right?
    >
    > I've come across this at a few of my client's sites but I haven't found out
    > why it happens. I seems that CDOSYS ends up using binary encoding rather
    > than Base64 encoding when creating the attachment body part. It doesn't
    > happen all system though.
    >
    > In the end I just used the following code to create the attachment myself:-
    >
    >
    > Function AddAttachment(Message, Source, FileName, MimeType)
    >
    > Dim oPart ' As IBodyPart
    > Dim oStreamIn ' As ADODB.Stream
    > Dim oStreamOut ' As ADODB.Stream
    >
    > Set oPart = Message.Attachments.Add
    >
    > oPart.ContentMediaType = MimeType & "; Name = """ & FileName & """"
    > oPart.ContentTransferEncoding = "base64"
    > oPart.Fields("urn:schemas:mailheader:content-disposition").Value =
    > "attachment; FileName = """ & FileName & """"
    > oPart.Fields.Update
    >
    > Set oStreamIn = Server.CreateObject("ADODB.Stream")
    >
    > oStreamIn.Open
    > oStreamIn.Type = adTypeBinary
    > oStreamIn.LoadFromFile Source
    >
    > Set oStreamOut = oPart.GetDecodedContentStream
    >
    > oStreamIn.CopyTo oStreamOut
    >
    > oStreamOut.Flush
    >
    > oStreamIn.Close
    >
    > Set AddAttachment = oPart
    >
    > End Function
    >
    >
    > Given a MyStuff.PDF in the folder C:\temp this function is called as:-
    >
    >
    >
    > Dim oMsg
    >
    > Set oMsg = Server.CreateObject("CDO.Message")
    >
    > 'Set From, To, etc.
    > oMsg.TextBody = "Blah Blah"
    >
    > AddAttachment oMsg, "c:\temp\MyStuff.pdf", "MyStuff.pdf", "application/pdf"
    >
    > oMsg.Send
    >
    >
    >
    > HTH
    >
    > Anthony.
    >
    >
    >
     
    rschaeferhig, Mar 28, 2006
    #4
  5. rschaeferhig

    sanj Guest

    I had the same problem, have you tried sending via CDNOTS?

    Sanj

    "rschaeferhig" wrote:

    > Oops.
    >
    > Windows 2000 Server AND Windows 2003 Server, but I'll give it a shot. I
    > suspected an encoding problem, I've just never had any experience doing my
    > own encoding so I had no idea where to start.
    >
    > thanks.
    >
    > "Anthony Jones" wrote:
    >
    > >
    > > "rschaeferhig" <> wrote in message
    > > news:...
    > > > I have an ASP page that uses CDOSYS to send a simple HTML format email

    > > with a
    > > > PDF attachment. When I open the PDF attached to the email it shows up as a
    > > > blank page. I log into the web server console and open the same PDF in the
    > > > source directory and it opens fine. I run a binary comparison of the

    > > source
    > > > and attached files and there's a difference: one byte, x'2E' is missing at
    > > > offset x'0231'. If I save the attached file and use a hex editor to insert
    > > > the x'2E' the file opens just like the original.
    > > >
    > > > Any ideas? I'm baffled...

    > >
    > > Windows 2003 server right?
    > >
    > > I've come across this at a few of my client's sites but I haven't found out
    > > why it happens. I seems that CDOSYS ends up using binary encoding rather
    > > than Base64 encoding when creating the attachment body part. It doesn't
    > > happen all system though.
    > >
    > > In the end I just used the following code to create the attachment myself:-
    > >
    > >
    > > Function AddAttachment(Message, Source, FileName, MimeType)
    > >
    > > Dim oPart ' As IBodyPart
    > > Dim oStreamIn ' As ADODB.Stream
    > > Dim oStreamOut ' As ADODB.Stream
    > >
    > > Set oPart = Message.Attachments.Add
    > >
    > > oPart.ContentMediaType = MimeType & "; Name = """ & FileName & """"
    > > oPart.ContentTransferEncoding = "base64"
    > > oPart.Fields("urn:schemas:mailheader:content-disposition").Value =
    > > "attachment; FileName = """ & FileName & """"
    > > oPart.Fields.Update
    > >
    > > Set oStreamIn = Server.CreateObject("ADODB.Stream")
    > >
    > > oStreamIn.Open
    > > oStreamIn.Type = adTypeBinary
    > > oStreamIn.LoadFromFile Source
    > >
    > > Set oStreamOut = oPart.GetDecodedContentStream
    > >
    > > oStreamIn.CopyTo oStreamOut
    > >
    > > oStreamOut.Flush
    > >
    > > oStreamIn.Close
    > >
    > > Set AddAttachment = oPart
    > >
    > > End Function
    > >
    > >
    > > Given a MyStuff.PDF in the folder C:\temp this function is called as:-
    > >
    > >
    > >
    > > Dim oMsg
    > >
    > > Set oMsg = Server.CreateObject("CDO.Message")
    > >
    > > 'Set From, To, etc.
    > > oMsg.TextBody = "Blah Blah"
    > >
    > > AddAttachment oMsg, "c:\temp\MyStuff.pdf", "MyStuff.pdf", "application/pdf"
    > >
    > > oMsg.Send
    > >
    > >
    > >
    > > HTH
    > >
    > > Anthony.
    > >
    > >
    > >
     
    sanj, Mar 29, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alejandro Penate-Diaz

    corrupted email attachments

    Alejandro Penate-Diaz, Mar 24, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    462
    Alejandro Penate-Diaz
    Mar 24, 2005
  2. =?Utf-8?B?Um9i?=

    SMTP Emailing with CDOSYS

    =?Utf-8?B?Um9i?=, Jul 9, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    332
    =?Utf-8?B?Um9i?=
    Jul 11, 2007
  3. codewarrior
    Replies:
    0
    Views:
    546
    codewarrior
    May 4, 2009
  4. Rohith KS
    Replies:
    1
    Views:
    130
  5. MM User

    CDOSYS SMTP

    MM User, Aug 3, 2008, in forum: ASP General
    Replies:
    1
    Views:
    127
    Anthony Jones
    Aug 3, 2008
Loading...

Share This Page