Visualizzazione dei risultati da 1 a 4 su 4
  1. #1

    Inviare più allegati tramite mail

    Salve ragazzi scusate ma ho un problema sull'invio di più allegati tramite mail.

    Vedendo in giro ho ricavato questo script che mi permtte di inviare tramite mail un'allegato.

    codice:
    <%
    Dim form, subject, allegato
    %>
    
    <Html>
    <head>
    <title>Email spedita</title>
    </head>
    <body>
    
    
    
    <%
    Dim oUpload 
    Set oUpload = new cUpload
    oUpload.SetPath "upload\"
    oUpload.Load
    if oUpload.Count=0 then
    	allegato = ""
    Else
    	While Not oUpload.EOF
    		oUpload.Save()
                    allegato = oUpload.GetFileName()
    		oUpload.MoveNext
    	Wend
    End if
    
    
    
    call Main()
    
    
    
    Sub Main()
    If Len(oUpload.Form("subject")) = 0 then
    no_sub()
    else 
    manda_posta(form)
    ecco_fatto(nome)
    end if
    Set oUpload=Nothing 
    End sub
    
    
    
    Sub no_sub()
    response.write "<div align='center'>"
    response.write "<table border='0' width='80%' cellspadding='4' cellspacing='4'>" 
    response.write "<tr><td>Non hai inserito un subject</td></tr>"
    response.write "<tr><td>Per favore, torna indiedro e inseriscine uno </td></tr>"
    response.write "<tr><td align='middlè>"
    response.write "<a href=java-script:history.go(-1)>Pagina precedente</a>"
    response.write "</td></tr></table></div>"
    End Sub
    
    
    
    Sub manda_posta(form)
    Dim subject, testo
    Dim objMail, objMailConfig
    subject = oUpload.Form("subject")
    mittente = oUpload.Form("mittente")
    testo = oUpload.Form("testo")
    Set objMail = Server.CreateObject("CDO.Message")
    Set objMailConfig = Server.CreateObject ("CDO.Configuration")
    
    ' Proprietà di invio
    with objMailConfig
      ' SMTP mail server
      .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.eurnetcity.net"
      ' SMTP port
      .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
      ' CDO port
      .Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
      ' Timeout
      .Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
      .Fields.Update
    end with
    
    Set objMail.Configuration = objMailConfig
    
    objMail.From = "r.didonato@infotrading.it"
    objMail.To = oUpload.Form("destinatario")
    objMail.Subject = subject
    objMail.TextBody = testo
    If Len(allegato) <> 0 then
    objMail.AddAttachment Server.MapPath("upload\" & allegato)
    end if
    objMail.Fields("urn:schemas:httpmail:importance").Value = 0
    objMail.Fields.update() 
    objMail.Send
    Set objMail = Nothing
    end sub
    
    
    
    Sub ecco_fatto(nome)
    response.write "<div align='center'>"
    response.write "<table border='0' width='80%' cellspadding='4' cellspacing='4'>" 
    response.write "<tr><td>Grazie " & subject & " per la mail</td></tr>"
    response.write "<tr><td align='middlè>"
    response.write "<a href=java-script:history.go(-2)>Torna indietro</a>"
    response.write "</td></tr></table></div>"
    End sub
    
    
    
    %>
    </body>
    </html>
    Il form invece è questo:
    codice:
    <HTML>
    <HEAD>
    <TITLE>Manda Email</TITLE>
    </HEAD>
    <BODY>
    
    <FORM ACTION="manda.asp" METHOD="post" enctype="multipart/form-data">
    
    <div align="center">
    <table border="0" width="85%" celpadding="2" cellspacing="2">
    
    <tr>
    <td>
    <h1>Manda E-mail<hr align="LEFT" size="1" width="100%" color="navy"></h1>
    </td>
    </tr>
    
    <tr>
    <td>
    Compila il Form
    </td>
    </tr>
    
    <td align="center">
    
    
    <table width="60%" border="0" celpadding="2" cellspacing="2">
    
    <tr>
    <td>Subject</td>
    <td><INPUT NAME="subject" TYPE="TEXT" size=30 MAXLENGTH=50></td>
    </tr>
    
    <tr>
    <td>Email destinatario</td>
    <td valign="top">
    <INPUT NAME="destinatario" TYPE="TEXT" ALIGN=left size=30 MAXLENGTH=50></td>
    </tr>
    
    <tr>
    <td valign="top">Testo</td>
    <td><TEXTAREA NAME="testo" ROWS=7 COLS=42></TEXTAREA></td>
    </tr>
    
    <tr>
    <td rowspan="3" valign="top">Allega</td>
    <td><input type="file" name="file1" /></td>
    </tr>
    <tr>
      <td><input type="file" type="file2"/></td>
    </tr>
    <tr>
     <td><input type="file" type="file3"/></td>
    </tr>
    
    
    <tr>
    <td colspan="2" align="center">
    <table width="50%" border="0" celpadding="6" cellspacing="2">
    
    <tr> 
      <td><input type="submit" name="invio" value="   Invia    "></td>
      <td align="right">
    <INPUT TYPE="reset" NAME="reset" VALUE="   Reset   "></td>
    </tr>
    </table></td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    </div>
    </FORM>
    </BODY>
    </HTML>
    Ora se carico tre foto lui mi fa arrivare in allegato sempre quella che carico nel terzo campo.

    Sul server invece me le carica tutte e tre.

    Potete cortesemente aiutarmi?

    Grazie in aticipo?


  2. #2
    Moderatore di ASP e MS Server L'avatar di Roby_72
    Registrato dal
    Aug 2001
    Messaggi
    19,559
    Nel momento in cui carichi le foto devi assegnare a tre variabili diverse ciascun file caricato.
    Devi in sostanza modificare questo:
    codice:
    	While Not oUpload.EOF
    		oUpload.Save()
                    allegato = oUpload.GetFileName()
    		oUpload.MoveNext
    	Wend
    E poi ovviamente ripetere questo per tre volte, mettendo le tre variabili:
    codice:
    objMail.AddAttachment Server.MapPath("upload\" & allegato)

    Roby

  3. #3
    Roby grazie per l'aiuto, sono riuscti a risolvere.

    Posto il codice qualora poosa tornare utile a qualcuno.


    Ecco quello dell' upload:
    codice:
    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <%
    Dim form, subject, allegato1, allegato2, allegato3
    %>
    
    <Html>
    <head>
    <title>Email spedita</title>
    </head>
    <body>
    
    
    
    <%
    Dim oUpload 
    Set oUpload = new cUpload
    oUpload.SetPath "upload\"
    oUpload.Load
    if oUpload.Count=0 then
    	allegato1 = ""
    	allegato2 = ""
    	allegato3 = ""
    Else
    	While Not oUpload.EOF
    		oUpload.Save()
    		Select Case lCase(oUpload.Files("InputName"))
    		Case "file1"
                    allegato1 = oUpload.GetFileName()
    		Case "file2"		
    				allegato2 = oUpload.GetFileName()
    		Case "file3"		
    				allegato3 = oUpload.GetFileName()
    		End Select
    		oUpload.MoveNext
    	Wend
    End if
    
    
    
    call Main()
    
    
    
    Sub Main()
    If Len(oUpload.Form("subject")) = 0 then
    no_sub()
    else 
    manda_posta(form)
    ecco_fatto(nome)
    end if
    Set oUpload=Nothing 
    End sub
    
    
    
    Sub no_sub()
    response.write "<div align='center'>"
    response.write "<table border='0' width='80%' cellspadding='4' cellspacing='4'>" 
    response.write "<tr><td>Non hai inserito un subject</td></tr>"
    response.write "<tr><td>Per favore, torna indiedro e inseriscine uno </td></tr>"
    response.write "<tr><td align='middlè>"
    response.write "<a href=java-script:history.go(-1)>Pagina precedente</a>"
    response.write "</td></tr></table></div>"
    End Sub
    
    
    
    Sub manda_posta(form)
    Dim subject, testo
    Dim objMail, objMailConfig
    subject = oUpload.Form("subject")
    mittente = oUpload.Form("mittente")
    testo = oUpload.Form("testo")
    Set objMail = Server.CreateObject("CDO.Message")
    Set objMailConfig = Server.CreateObject ("CDO.Configuration")
    
    ' Proprietà di invio
    with objMailConfig
      ' SMTP mail server
      .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.eurnetcity.net"
      ' SMTP port
      .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
      ' CDO port
      .Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
      ' Timeout
      .Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
      .Fields.Update
    end with
    
    Set objMail.Configuration = objMailConfig
    
    objMail.From = "r.didonato@infotrading.it"
    objMail.To = oUpload.Form("destinatario")
    objMail.Subject = subject
    objMail.TextBody = testo
    If Len(allegato1) <> 0 then
    objMail.AddAttachment Server.MapPath("upload\" & allegato1)
    end if
    If Len(allegato2) <> 0 then
    objMail.AddAttachment Server.MapPath("upload\" & allegato2)
    end if
    If Len(allegato3) <> 0 then
    objMail.AddAttachment Server.MapPath("upload\" & allegato3)
    end if
    objMail.Fields("urn:schemas:httpmail:importance").Value = 0
    objMail.Fields.update() 
    objMail.Send
    Set objMail = Nothing
    end sub
    
    
    
    Sub ecco_fatto(nome)
    response.write "<div align='center'>"
    response.write "<table border='0' width='80%' cellspadding='4' cellspacing='4'>" 
    response.write "<tr><td>Grazie " & subject & " per la mail</td></tr>"
    response.write "<tr><td align='middlè>"
    response.write "<a href=java-script:history.go(-2)>Torna indietro</a>"
    response.write "</td></tr></table></div>"
    End sub
    
    
    
    %>
    </body>
    </html>
    Questo invece è quello del form:

    codice:
    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <HTML>
    <HEAD>
    <TITLE>Manda Email</TITLE>
    </HEAD>
    <BODY>
    
    <FORM ACTION="manda.asp" METHOD="post" enctype="multipart/form-data">
    
    <div align="center">
    <table border="0" width="85%" celpadding="2" cellspacing="2">
    
    <tr>
    <td>
    <h1>Manda E-mail<hr align="LEFT" size="1" width="100%" color="navy"></h1>
    </td>
    </tr>
    
    <tr>
    <td>
    Compila il Form
    </td>
    </tr>
    
    <td align="center">
    
    
    <table width="60%" border="0" celpadding="2" cellspacing="2">
    
    <tr>
    <td>Subject</td>
    <td><INPUT NAME="subject" TYPE="TEXT" size=30 MAXLENGTH=50></td>
    </tr>
    
    <tr>
    <td>Email destinatario</td>
    <td valign="top">
    <INPUT NAME="destinatario" TYPE="TEXT" ALIGN=left size=30 MAXLENGTH=50></td>
    </tr>
    
    <tr>
    <td valign="top">Testo</td>
    <td><TEXTAREA NAME="testo" ROWS=7 COLS=42></TEXTAREA></td>
    </tr>
    
    <tr>
    <td rowspan="3" valign="top">Allega</td>
    <td><input type="file" name="file1" /></td>
    </tr>
    <tr>
      <td><input type="file" name="file2" /></td>
    </tr>
    <tr>
      <td><input type="file" name="file3" /></td>
    </tr>
    
    
    <tr>
    <td colspan="2" align="center">
    <table width="50%" border="0" celpadding="6" cellspacing="2">
    
    <tr> 
      <td><input type="submit" name="invio" value="   Invia    "></td>
      <td align="right">
    <INPUT TYPE="reset" NAME="reset" VALUE="   Reset   "></td>
    </tr>
    </table></td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    </div>
    </FORM>
    </BODY>
    </HTML>
    Ciao e grazie ancora.


  4. #4
    Buongiorno a tutti!

    Riprendo questo vecchio post perchè mi è tornato utile molte volte!

    Da questa base è possibile ipotizzare un invio di n allegati, dove n è un numero che varia in base al numero di input file presenti nel form?


Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.