Classic ASP, Email form with streamed attachment

Associate
Joined
13 Jul 2005
Posts
737
Location
Brisbane
Hi All,

I'm trying to figure out how i can submit an email using classic asp to an address and stream the attachment.

So far this is what i have got, it's a medley of 2 scripts, and i am unsure on the streaming part.

Form:

Code:
<form action="upload.asp" method="post" enctype="multipart/form-data">
<INPUT TYPE="file" NAME="FileUpload1" id="FileUpload1" MAXLENGTH=50>
<input type="submit" name="Submit" value="Submit" />
</form>


Upload.asp

Code:
<%

If FileUpload1.HasFile Then

 Dim ObjSendMail
 Set ObjSendMail = CreateObject("CDO.Message") 
      
      
 ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'Send the message using the network (SMTP over the network).
 ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") ="my.SMTPServer.com"
 ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
 ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False 'Use SSL for the connection (True or False)
 ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
      

 ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic (clear-text) authentication
 ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") ="Username"
 ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") ="Password"
      
 ObjSendMail.Configuration.Fields.Update
        
 ObjSendMail.To = "[email protected]"
 ObjSendMail.Subject = "this is the subject"
 ObjSendMail.From = "[email protected]"
      

 'ObjSendMail.HTMLBody = "this is the body"
 ObjSendMail.TextBody = "this is the body"
 ObjSendMail.AddAttachment=Request.Form("FileUpload1")
 
Const cdoContentDispostion = "urn:schemas:mailheader:content-disposition"
Const cdoBase64 = "base64"

Set oPart = ObjSendMail.Attachments.Add

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

oPart.Fields(cdoContentDisposition).Value = Request.Form("FileUpload1")
oPart.Fields.Update

Set oStreamOut = oPart.GetDecodedContentStream
oStreamOut.Write aByt
oStreamOut.Flush
      
ObjSendMail.Send
      
Set ObjSendMail = Nothing 
End If
%>

Help is much appreciated.

Tucks
 
Thanks, i've decided to merge the below into the script, taken from: http://bytes.com/topic/asp-classic/answers/473374-asp-cdosys-smtp-email-attachments-being-corrupted

Code:
 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

but it is getting stuck on:

Code:
Syntax error 

/cvupload.asp, line 40 

oPart.Fields("urn:schemas:mailheader:content-disposition").Value =

Do you know how i can point:
Code:
 oPart.Fields("urn:schemas:mailheader:content-disposition").Value =
 "attachment; FileName = """ & FileName & """"

To the attachment field in my form?

Thanks a lot
 
Back
Top Bottom