ASPmail med attachments og insert record problem!
Hej,Jeg benytter ASPmail fra UltraDev Exchange og ønsker at benytte attachments v.h.a. et filefield til at
browse de ønskede filer. Men jeg modtager mærkeligt nok følgende fejl:
error \'80004005\'
Unspecified error
/web_mails/webmail/test2.asp, line 103
...og dette er linie 103: ObjCDO.AttachFile(Emattach)
jeg ville også gerne kunne sende en email, attache en fil og dernæst indsætte indholdet i en database
(.mdb) på samme tid. Men det er næste skridt. Her er min komplette kode:
<%@LANGUAGE=\"VBSCRIPT\"%><%
\' *** Insert Record: construct a sql insert statement and execute it
MM_editAction = CStr(Request(\"URL\"))
If (Request.QueryString <> \"\") Then
MM_editAction = MM_editAction & \"?\" & Request.QueryString
End If
If (CStr(Request(\"MM_insert\")) <> \"\") Then
MM_tableName = \"canned\"
MM_fields = \"to,to,\',none,\'\',cc,cc,\',none,\'\',subject,subject,\',none,\'\',message,message,\',none,\'\'\"
MM_redirectPage = \"\"
\' create the insert sql statement
MM_tableValues = \"\"
MM_dbValues = \"\"
MM_fieldsArray = Split(MM_fields, \",\")
For i = LBound(MM_fieldsArray) To UBound(MM_fieldsArray) Step 5
FormVal = CStr(Request.Form(MM_fieldsArray(i)))
Delim = MM_fieldsArray(i+2)
If (Delim = \"none\") Then Delim = \"\"
AltVal = MM_fieldsArray(i+3)
If (AltVal = \"none\") Then AltVal = \"\"
EmptyVal = MM_fieldsArray(i+4)
If (EmptyVal = \"none\") Then EmptyVal = \"\"
If (FormVal = \"\") Then
FormVal = EmptyVal
Else
If (AltVal <> \"\") Then
FormVal = AltVal
ElseIf (Delim = \"\'\") Then \' escape quotes
FormVal = \"\'\" & Replace(FormVal,\"\'\",\"\'\'\") & \"\'\"
Else
FormVal = Delim + FormVal + Delim
End If
End If
If (i <> LBound(MM_fieldsArray)) Then
MM_tableValues = MM_tableValues & \",\"
MM_dbValues = MM_dbValues & \",\"
End if
MM_tableValues = MM_tableValues & MM_fieldsArray(i+1)
MM_dbValues = MM_dbValues & FormVal
Next
MM_insertStr = \"insert into \" & MM_tableName & \" (\" & MM_tableValues & \") values (\" & MM_dbValues &
\")\"
\' finish the sql and execute it
Set MM_insertCmd = Server.CreateObject(\"ADODB.Command\")
MM_insertCmd.ActiveConnection = \"dsn=webmail;\"
MM_insertCmd.CommandText = MM_insertStr
MM_insertCmd.Execute
\' redirect with URL parameters
If (MM_redirectPage = \"\") Then
MM_redirectPage = CStr(Request(\"URL\"))
End If
If (InStr(1, MM_redirectPage, \"?\", vbTextCompare) = 0 And (Request.QueryString <> \"\")) Then
MM_redirectPage = MM_redirectPage & \"?\" & Request.QueryString
End If
Call Response.Redirect(MM_redirectPage)
End If
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">
</head>
<body bgcolor=\"#FFFFFF\">
<form name=\"form1\" method=\"post\" action=\"<%=MM_editAction%>\" enctype=\"multipart/form-data\">
<p>to
<input type=\"text\" name=\"to\">
</p>
<p>cc
<input type=\"text\" name=\"cc\">
</p>
<p>subject
<input type=\"text\" name=\"subject\">
</p>
<p> message
<input type=\"text\" name=\"message\">
<br>
<input type=\"file\" name=\"file\">
<%
Dim Emfrom
Dim Emsub
Dim Emto
Dim Emcc
Dim Embody
Dim Emattach
Emfrom = \"mads@mads.dk\"
Emsub = Request.Form(\"subject\")
Emto = Request.Form(\"to\")
Emcc = Request.Form(\"cc\")
Embody = Request.Form(\"message\")
Emattach = Request.Form(\"file\")
Dim ObjCdo
Set ObjCdo = Server.CreateObject(\"CDONTS.NewMail\")
ObjCdo.From = Emfrom
ObjCdo.Subject = Emsub
ObjCdo.To = Emto
ObjCdo.cc = Emcc
ObjCdo.body = Embody
ObjCDO.AttachFile(Emattach)
ObjCdo.send
Set ObjCdo = nothing
%></p>
<p>
<input type=\"submit\" name=\"Submit\" value=\"Submit\">
</p>
<input type=\"hidden\" name=\"MM_insert\" value=\"true\">
</form>
</body>
</html>
Jeg venter med længsel på hjælp - på forhånd tak!
Bambino