Create an email attachment using a stream in classic ASP (not ASP.Net)

Discussion in 'ASP General' started by brendan_gallagher_2001, Nov 8, 2006.

  1. Hi,

    Does anyone know how to create an attachment using a stream in classic

    I can see that it can be done in ASP.Net as per the article below:
    Initializes a new instance of the Attachment class with the specified
    stream and name.

    Any help is greatly appreciated.

    brendan_gallagher_2001, Nov 8, 2006
    1. Advertisements

  2. brendan_gallagher_2001

    Slim Guest

    1. Advertisements

  3. Thanks. I should have also mentioned in my original query that I want
    to avoid creating a file on any directory. I just want to set the
    content of the attachement to the content of a stream.
    brendan_gallagher_2001, Nov 8, 2006
  4. Heres an example:-

    Const cdoContentDispostion = "urn:schemas:mailheader:content-disposition"
    Const cdoBase64 = "base64"

    Set oPart = oMsg.Attachments.Add

    oPart.ContentMediaType = "application/octet-stream"
    oPart.ContentTransferEncoding = cdoBase64

    oPart.Fields(cdoContentDisposition).Value = "attachment;

    Set oStreamOut = oPart.GetDecodedContentStream
    oStreamOut.Write aByt

    Where oMsg is an existing cdoMessage (ensure you've added any text and/or
    html bodies first) and abyt is the set of bytes that represents the resource
    to attach.

    What type of content are you attaching?
    Anthony Jones, Nov 8, 2006
  5. Hi Anthony,

    Thanks for the example. I'll test shortly. I am attaching plain text.

    brendan_gallagher_2001, Nov 8, 2006
  6. In that case I'll adjust the example:-

    Const cdoContentDisposition = "urn:schemas:mailheader:content-disposition"

    Dim oPart : Set oPart = oMsg.Attachments.Add

    oPart.ContentMediaType = "text/plain; charset=iso-8859-1"
    oPart.CharSet = "iso-8859-1"
    oPart.ContentTransferEncoding = "quoted-printable"

    oPart.Fields(cdoContentDisposition).Value =

    Dim oStreamOut: Set oStreamOut = oPart.GetDecodedContentStream
    oStreamOut.WriteText sContent

    Where sContent is the string content you want to include in the email
    Anthony Jones, Nov 8, 2006
  7. Thanks Anthony. Your code works perfectly.
    brendan_gallagher_2001, Nov 13, 2006
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.