salve a tutti...
Ho preso dal vs forum tutta una serie di script per realizzare una mailing list con cdonts e di inviare poi il contenuto al db e va alla grande, ma adesso sorge un problemino...
Devo poter uplodore un file (contemporaneamente all'invio della mail) che poi richiamo con un link dal db!
Ho prelevato da aruba uno script che da solo funziona ma che se lo inserisco nel sodice della mail mi da un errore del tipo "HTTP 500".
Ho provato a fare delle piccole prove e:
Se elimino ENCTYPE="multipart/form-data" da <form action="mailing.asp" ENCTYPE="multipart/form-data" method="POST" > la mailing funziona ma non invia il file...viceversa nopn invia ne il file ne l'email....
Come faccio????
Vi allego lo script.
pagina request.asp (la prima da cui prelevo i dati)
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="Connections/display.asp" -->
<%
set display = Server.CreateObject("ADODB.Recordset")
display.ActiveConnection = MM_display_STRING
display.Source = "SELECT * FROM news ORDER BY data DESC"
display.CursorType = 0
display.CursorLocation = 2
display.LockType = 3
display.Open()
display_numRows = 0
%>
<%
' *** Recordset Stats, Move To Record, and Go To Record: declare stats variables
' set the record count
display_total = display.RecordCount
' set the number of rows displayed on this page
If (display_numRows < 0) Then
display_numRows = display_total
Elseif (display_numRows = 0) Then
display_numRows = 1
End If
' set the first and last displayed record
display_first = 1
display_last = display_first + display_numRows - 1
' if we have the correct record count, check the other stats
If (display_total <> -1) Then
If (display_first > display_total) Then display_first = display_total
If (display_last > display_total) Then display_last = display_total
If (display_numRows > display_total) Then display_numRows = display_total
End If
%>
<%
' *** Recordset Stats: if we don't know the record count, manually count them
If (display_total = -1) Then
' count the total records by iterating through the recordset
display_total=0
While (Not display.EOF)
display_total = display_total + 1
display.MoveNext
Wend
' reset the cursor to the beginning
If (display.CursorType > 0) Then
display.MoveFirst
Else
display.Requery
End If
' set the number of rows displayed on this page
If (display_numRows < 0 Or display_numRows > display_total) Then
display_numRows = display_total
End If
' set the first and last displayed record
display_first = 1
display_last = display_first + display_numRows - 1
If (display_first > display_total) Then display_first = display_total
If (display_last > display_total) Then display_last = display_total
End If
%>
<html>
<script language="JavaScript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
// -->
</script>
<body bgcolor="#FFFFFF">
<div id="Layer1" style="position:absolute; left:403px; top:39px; width:309px; height:183px; z-index:1">
<p><b>Sono state scritte <%=(display_total)%> newsletter.</b></p>
<p><b>L'ultima è del <%=(display.Fields.Item("data").Value)%>.</b></p>
</div>
<form action="mailing.asp" ENCTYPE="multipart/form-data" method="POST" >
<p> <b>Oggetto:</b>
<input type="text" size="25" name="oggetto">
</p>
<p><b>Abstract:</b>
<input type="text" name="abstract" id="abstract">
</p>
<p> <b>Priorità:</b>
<select name="priorita" size="1">
<option value="2">Alta</option>
<option selected value="1">Normale</option>
<option value="0">Bassa</option>
</select>
</p>
<p> <b>Testo da inviare agli iscritti.</b></p>
<p>
<textarea name="testo" rows="17" cols="60"></textarea>
</p>
<p><b>Download Documento: </b>
<input type="text" name="download" value="public/">
(aggiungi il nome del file dopo public/ completo di estenzione)</p>
<p>Invia il documento
<input type="file" name="blob">
</p>
<p>
<input type="submit" name="Enter" value="Invia messaggi">
<input type="reset" name="B2" value="Reimposta">
</p>
</form>
</body>
<%
display.Close()
%>
pagina 2 mailing.asp (mi processa l'invio dell'email l'insert into al db e dovrebbe farmi fare upload del file).
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="upload.asp"-->
<%Response.Expires=0
Response.Buffer = TRUE
Response.Clear
byteCount = Request.TotalBytes
RequestBin = Request.BinaryRead(byteCount)
Dim UploadRequest
Set UploadRequest = CreateObject("Scripting.Dictionary")
BuildUploadRequest RequestBin
contentType = UploadRequest.Item("blob").Item("ContentType")
filepathname = UploadRequest.Item("blob").Item("FileName")
filename = Right(filepathname,Len(filepathname)-InstrRev(filepathname,"\"))
value = UploadRequest.Item("blob").Item("Value")
'Creo FileSytemObject Component
Set ScriptObject = Server.CreateObject("Scripting.FileSystemObject")
'Creo e scrivo il file
pathEnd = Len(Server.mappath(Request.ServerVariables("PATH_INFO")))-14
Set MyFile = ScriptObject.CreateTextFile(Left(Server.mappath(Request.ServerVariables("PATH_INFO")),pathEnd) & filename)
For i = 1 to LenB(value)
MyFile.Write chr(AscB(MidB(value,i,1)))
Next%>
<%
'richiamo i dati provenienti dal form
oggetto=request.form("oggetto")
priorita=request.form("priorita")
testo=request.form("testo")
download=request.form("download")
abstract=request.form("abstract")
'invio i dati al database news
dim conn
set conn = Server.CreateObject("ADODB.Connection")
conn.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & server.MapPath("../mdb-database/news.mdb")
dim rs
set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "INSERT INTO news (titolo_notizia, testo_notizia, download, abstract) values ('"& request.form("oggetto") &"','" & request.form ("testo") &"','"& request.form("download") &"','"& request.form("abstract") &"')", conn
' processo l'invio della email
dim dove
dove="driver={Microsoft Access Driver (*.mdb)};dbq="& server.mappath("../mdb-database/registrazione.mdb")
Set rs=Server.CreateObject("ADODB.recordset")
dim stmsql
stmsql="Select nome,email FROM anagrafica"
rs.Open stmsql,dove
do while not rs.EOF
Set objMail = Server.CreateObject("CDONTS.NewMail")
danome="archeopaestum.com"
damail="<news@archeopaestum.com>"
dachi=chr(34) & danome & chr(34) & damail
objMail.From=dachi
'inserisco nel body della mail il testo e il link al download
objMail.Body=testo & VBCRLF & download
objMail.To=chr(34) & rs("nome") & chr(34) &"<"& rs("email")&">"
objMail.Subject=oggetto
objmail.importance=priorita
objMail.Send
set objMail = nothing
rs.MoveNext
loop
rs.close
Set rs = NOTHING
MyFile.Close
'T2-NET creation
%>
<script language="javascript">
{
setTimeout ('parent.location.href="../default.asp"', 1000);
}
</script>
allego il file di inclusione di mailing.asp.
<%Sub BuildUploadRequest(RequestBin)
PosBeg = 1
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
boundary = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
boundaryPos = InstrB(1,RequestBin,boundary)
Do until (boundaryPos=InstrB(RequestBin,boundary & getByteString("--")))
Dim UploadControl
Set UploadControl = CreateObject("Scripting.Dictionary")
Pos = InstrB(BoundaryPos,RequestBin,getByteString("Content-Disposition"))
Pos = InstrB(Pos,RequestBin,getByteString("name="))
PosBeg = Pos+6
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34)))
Name = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
PosFile = InstrB(BoundaryPos,RequestBin,getByteString("filename="))
PosBound = InstrB(PosEnd,RequestBin,boundary)
If PosFile<>0 AND (PosFile<PosBound) Then
PosBeg = PosFile + 10
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34)))
FileName = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
UploadControl.Add "FileName", FileName
Pos = InstrB(PosEnd,RequestBin,getByteString("Content-Type:"))
PosBeg = Pos+14
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
ContentType = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
UploadControl.Add "ContentType",ContentType
PosBeg = PosEnd+4
PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
Value = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
Else
Pos = InstrB(Pos,RequestBin,getByteString(chr(13)))
PosBeg = Pos+4
PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
Value = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
End If
UploadControl.Add "Value" , Value
UploadRequest.Add name, UploadControl
BoundaryPos=InstrB(BoundaryPos+LenB(boundary),RequestBin,boundary)
Loop
End Sub
Function getByteString(StringStr)
For i = 1 to Len(StringStr)
char = Mid(StringStr,i,1)
getByteString = getByteString & chrB(AscB(char))
Next
End Function
Function getString(StringBin)
getString =""
For intCount = 1 to LenB(StringBin)
getString = getString & chr(AscB(MidB(StringBin,intCount,1)))
Next
End Function%>
NB. i file sono inseriti nella cartella PUBLIC di un server ARUBA, in cui ho i diritti per la scrittura di file.
A questo punto sono nelle vostre mani...perchè la mie mi sono state amputate!
GRAZIE a TUTTI