how to attach files to email without saving them onto the diskRSS

4 replies

Last post Jul 24, 2019 08:45 PM by Slickhead

  • how to attach files to email without saving them onto the disk

    Jan 30, 2012 08:45 AM|kevin.j.roy|LINK

     Hi, I'm working with VB.NET and trying to attach a file on the fly to an email. I have a form with <input type="file"> that I want to attach to an email.

    I have seen some code that utilizes ADODB.Stream but not too sure how it works. Anyone knows how to do this ?

            

                set objStream = Server.CreateObject("ADODB.Stream")
                objStream.Type  = 1
                objStream.Open
                objStream.Mode = adModeReadWrite

    I need to find  a way to attach the objStream file to my Mail class...

     


    classic asp mail stream attachment

  • Re: how to attach files to email without saving them onto the disk

    Feb 01, 2012 02:27 AM|Lloydz|LINK

    Hi,

    As far as I know, for classic asp you can use the built-in CDOSYS component to send e-mails. The following article contains samples including add an attachment:

    ASP Sending e-mail with CDOSYS
    http://www.w3schools.com/asp/asp_send_email.asp

    Hope this helpful for you, thanks.

     

  • Re: how to attach files to email without saving them onto the disk

    Feb 01, 2012 07:05 AM|kevin.j.roy|LINK

    Thanks for your reply,

    Unfortunately that does not help. The example you provided showed how to send an attachment located on the server. I am trying to attach the file "on the fly", meaning the attachment cannot be saved physically on the server. 

    From what I have been able to Google up to now, it seems I need to keep the file in a 'binary stream' --->  Server.CreateObject("ADODB.Stream"), then serialize the binary object, and then attach it (easy to google, I don't need help with that).

     What I cannot Google is how to attach on the fly.

    I did find this link which seemed to help but I cannot understand it.

    http://bytes.com/topic/asp-classic/answers/560826-create-email-attachment-using-stream-classic-asp-not-asp-net

     

  • Re: how to attach files to email without saving them onto the disk

    Feb 08, 2012 07:32 AM|kevin.j.roy|LINK

     I used the clsUpload file which is easily googleable and modified their save function to attach a file on the fly

     


            binData = o.BinaryDataOf("InputFieldNameFromSubmissionForm") <-- BinaryDataOf is a function from the clsUpload class
       
            set rs = server.createobject("ADODB.RECORDSET")
            rs.fields.append "FileName", 205, LenB(binData)
            rs.open
            rs.addnew
             rs.fields(0).AppendChunk binData
           
            if err.number = 0 then
           
               
                Set objMessage = CreateObject("CDO.Message")
                ...

                objMessage.Configuration.Fields.Item _
                ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
               
                objMessage.Configuration.Fields.Update

                binData = rs.fields("FileName").value
               
                Const cdoContentDisposition = "urn:schemas:mailheader:content-disposition"
                Const cdoBase64 = "base64"
               
                Dim oPart : Set oPart = objMessage.Attachments.Add
               
                oPart.ContentMediaType = "application/octet-stream"
                'oPart.CharSet = "iso-8859-1"
                oPart.ContentTransferEncoding = cdoBase64'"quoted-printable"
               
                oPart.Fields(cdoContentDisposition).Value = "attachment;filename=""Test.jpg"""

                oPart.Fields.Update
               
                Dim oStreamOut: Set oStreamOut = oPart.GetDecodedContentStream
                'oStreamOut.WriteText sContent
                oStreamOut.Write binData
                oStreamOut.Flush
               
                objMessage.Send

            ENd if
            rs.close

  • Re: how to attach files to email without saving them onto the disk

    Jul 24, 2019 08:45 PM|Slickhead|LINK

    Many thanks. This works great, however, I can't figure out how to send other text fields that may be included in the form (e.g. Name, Address, Email). I can't use request.form when doing a binary read. Head scratcher. Do you have any modified code demonstrating this?