IIS 5 & IIS 6
how to attach files to email without saving them onto the disk
Last post Jul 24, 2019 08:45 PM by Slickhead
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.Mode = adModeReadWrite
Feb 01, 2012 02:27 AM|Lloydz|LINK
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
Hope this helpful for you, thanks.
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' --->
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.
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)
if err.number = 0 then
Set objMessage = CreateObject("CDO.Message")
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
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"""
Dim oStreamOut: Set oStreamOut = oPart.GetDecodedContentStream
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